diff options
Diffstat (limited to 'vhosts/blog/nuldoc-src')
| -rw-r--r-- | vhosts/blog/nuldoc-src/jsx/types.d.ts | 6 | ||||
| -rw-r--r-- | vhosts/blog/nuldoc-src/ndoc/to_html.ts | 17 | ||||
| -rw-r--r-- | vhosts/blog/nuldoc-src/pages/AboutPage.tsx | 20 |
3 files changed, 39 insertions, 4 deletions
diff --git a/vhosts/blog/nuldoc-src/jsx/types.d.ts b/vhosts/blog/nuldoc-src/jsx/types.d.ts index 5d949d14..e47d7ffe 100644 --- a/vhosts/blog/nuldoc-src/jsx/types.d.ts +++ b/vhosts/blog/nuldoc-src/jsx/types.d.ts @@ -32,7 +32,11 @@ declare global { summary: IntrinsicElementType; updated: IntrinsicElementType; // HTML - a: IntrinsicElementType & { href?: string }; + a: IntrinsicElementType & { + href?: string; + rel?: "noreferrer"; + target?: "_blank"; + }; article: IntrinsicElementType; body: IntrinsicElementType; button: IntrinsicElementType; diff --git a/vhosts/blog/nuldoc-src/ndoc/to_html.ts b/vhosts/blog/nuldoc-src/ndoc/to_html.ts index ce55dbf9..bf556655 100644 --- a/vhosts/blog/nuldoc-src/ndoc/to_html.ts +++ b/vhosts/blog/nuldoc-src/ndoc/to_html.ts @@ -21,6 +21,7 @@ export default function toHtml(doc: Document): Document { transformSectionTitleElement(doc); transformCodeBlockElement(doc); transformNoteElement(doc); + addAttributesToExternalLinkElement(doc); setDefaultLangAttribute(doc); traverseFootnotes(doc); highlightPrograms(doc); @@ -211,6 +212,22 @@ function transformNoteElement(doc: Document) { }); } +function addAttributesToExternalLinkElement(doc: Document) { + forEachChildRecursively(doc.root, (n) => { + if (n.kind !== "element" || n.name !== "a") { + return; + } + + const href = n.attributes.get("href") ?? ""; + if (!href.startsWith("http")) { + return; + } + n.attributes + .set("target", "_blank") + .set("rel", "noreferrer"); + }); +} + function setDefaultLangAttribute(_doc: Document) { // TODO // if (!e.attributes.has("lang")) { diff --git a/vhosts/blog/nuldoc-src/pages/AboutPage.tsx b/vhosts/blog/nuldoc-src/pages/AboutPage.tsx index 0000edf5..48763821 100644 --- a/vhosts/blog/nuldoc-src/pages/AboutPage.tsx +++ b/vhosts/blog/nuldoc-src/pages/AboutPage.tsx @@ -44,12 +44,22 @@ export default function AboutPage( <h2>アカウント</h2> <ul> <li> - <a href="https://twitter.com/nsfisis"> + <a + href="https://twitter.com/nsfisis" + target="_blank" + rel="noreferrer" + > Twitter (現 𝕏): @nsfisis </a> </li> <li> - <a href="https://github.com/nsfisis">GitHub: @nsfisis</a> + <a + href="https://github.com/nsfisis" + target="_blank" + rel="noreferrer" + > + GitHub: @nsfisis + </a> </li> </ul> </section> @@ -58,7 +68,11 @@ export default function AboutPage( <ul> <li> {"2021-01~現在: "} - <a href="https://www.dgcircus.com/"> + <a + href="https://www.dgcircus.com/" + target="_blank" + rel="noreferrer" + > デジタルサーカス株式会社 </a> </li> |
