From 9127d1c420420b3c80414d8222840e96e4dd3f18 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 26 Jan 2025 15:23:17 +0900 Subject: feat(blog/nuldoc): add `target=_blank` and `rel=noreferrer` to external links --- vhosts/blog/nuldoc-src/jsx/types.d.ts | 6 +++++- vhosts/blog/nuldoc-src/ndoc/to_html.ts | 17 +++++++++++++++++ vhosts/blog/nuldoc-src/pages/AboutPage.tsx | 20 +++++++++++++++++--- vhosts/blog/public/about/index.html | 6 +++--- .../posts/2021-03-30/phperkaigi-2021/index.html | 2 +- .../index.html | 10 +++++----- .../2021-10-02/python-unbound-local-error/index.html | 2 +- .../ruby-detect-running-implementation/index.html | 10 +++++----- .../ruby-then-keyword-and-case-in/index.html | 4 ++-- .../rust-where-are-primitive-types-from/index.html | 4 ++-- .../index.html | 12 ++++++------ .../vim-swap-order-of-selected-lines/index.html | 2 +- .../2022-04-09/phperkaigi-2022-tokens/index.html | 8 ++++---- .../index.html | 6 +++--- .../posts/2022-05-01/phperkaigi-2022/index.html | 18 +++++++++--------- .../php-conference-okinawa-code-golf/index.html | 8 ++++---- .../index.html | 6 +++--- .../index.html | 2 +- .../phperkaigi-2023-unused-token-quiz-1/index.html | 2 +- .../2022-10-28/setup-server-for-this-site/index.html | 4 ++-- .../phperkaigi-2023-unused-token-quiz-2/index.html | 4 ++-- .../phperkaigi-2023-unused-token-quiz-3/index.html | 4 ++-- .../rewrite-this-blog-generator/index.html | 4 ++-- .../index.html | 8 ++++---- .../2023-04-04/phperkaigi-2023-report/index.html | 16 ++++++++-------- .../2023-06-25/phpconfuk-2023-report/index.html | 14 +++++++------- .../compile-php-runtime-to-wasm/index.html | 18 +++++++++--------- .../public/posts/2023-12-03/isucon-13/index.html | 4 ++-- .../posts/2023-12-31/2023-reflections/index.html | 6 +++--- .../index.html | 2 +- .../install-wireguard-on-personal-server/index.html | 2 +- .../2024-02-10/yapcjapan-2024-report/index.html | 10 +++++----- .../2024-02-22/phpkansai-2024-report/index.html | 10 +++++----- .../2024-03-17/phperkaigi-2024-report/index.html | 14 +++++++------- .../2024-04-14/phpcon-odawara-2024-report/index.html | 12 ++++++------ .../pipefail-option-in-gitlab-ci-cd/index.html | 4 ++-- .../index.html | 2 +- .../2024-05-11/phpconkagawa-2024-report/index.html | 12 ++++++------ .../2024-06-19/scalamatsuri-2024-report/index.html | 12 ++++++------ .../reparojson-fix-only-json-formatter/index.html | 6 +++--- .../index.html | 6 +++--- .../posts/2024-09-28/mncore-challenge-1/index.html | 4 ++-- .../posts/2024-12-04/cohackpp-report/index.html | 8 ++++---- .../posts/2024-12-33/2024-reflections/index.html | 6 +++--- .../2025-01-08/phperkaigi-2023-tokens-q1/index.html | 8 ++++---- .../index.html | 4 ++-- 46 files changed, 192 insertions(+), 157 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(

アカウント

@@ -58,7 +68,11 @@ export default function AboutPage(