/
githubmirror
/
hexo
Обзор
Документация
Войти
/
githubmirror
/
hexo
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
lib/plugins/helper/link_to.ts
47 строк
1 KB
D-Sketon
refactor: migrate typescript (#5417)
03 мар 2024, 11:04
Не верифицирован
03 мар 2024, 11:04
3c7729d
Код
Авторство
О чём код?
import { htmlTag, url_for } from 'hexo-util'; import type { LocalsType } from '../../types'; interface Options { id?: string; href?: string; title?: string; external?: boolean | null; class?: string | string[]; target?: string; rel?: string; } interface Attrs { href: string; title: string; external?: boolean | null; class?: string; target?: string; rel?: string; [key: string]: string | boolean | null | undefined; } function linkToHelper(this: LocalsType, path: string, text?: string, options: Options | boolean = {}) { if (typeof options === 'boolean') options = {external: options}; if (!text) text = path.replace(/^https?:\/\/|\/$/g, ''); const attrs = Object.assign({ href: url_for.call(this, path) as string, title: text }, options); if (attrs.external) { attrs.target = '_blank'; attrs.rel = 'noopener'; attrs.external = null; } if (attrs.class && Array.isArray(attrs.class)) { attrs.class = attrs.class.join(' '); } return htmlTag('a', attrs as Attrs, text); } export = linkToHelper;