LoginSignup
0
1

短縮URLを静的に実装する話

Last updated at Posted at 2023-09-15

但し書き

本件、小ネタです。目からウロコというか、世の中にはいろんなこと考える人いるなぁというか、そんな話。

まずは評価

タグにつけておりまして、本記事は #製品評価 です。

オンプレミス環境で、短縮URLを実装できないかと探索、suri というプロダクトを試してみました。
どこの紹介サイトか、どこのaltサイトで見たかも忘れましたが。。
先に結論を申し上げると、そこあまり重要じゃないので割愛。

試用

githubのREADME.mdのとおりですので、まずはためしてみます。

git clone https://github.com/jstayton/suri
cd suri
npm install

なにやら本日時点でこんなん出てます。

found 23 vulnerabilities (11 moderate, 6 high, 6 critical)
  run `npm audit fix` to fix them, or `npm audit` for details

わざわざ警告いただいたので、とりあえず npm audit fix を実施。
(結論を考えると、これはあまり意味ない)

fixed 15 of 23 vulnerabilities in 665 scanned packages
  7 vulnerabilities required manual review and could not be updated
  1 package update for 1 vulnerability involved breaking changes
  (use `npm audit fix --force` to install breaking changes; or refer to `npm audit` for steps to fix these manually)

残り7+1があるとのことだけど、とりあえず放置して先にすすむ。

npm run build

なにも考えずに実行しましたが、Windows環境だとここでコケます。
こんなんエラー出る。

npm ERR! suri@0.5.1 build: `npm run clean && NODE_ENV=production eleventy`

eleventy ってなんぞ??
はい、 node.js ベースの静的コンテンツ生成ツールのようです。。。

詳細確認する余裕ないので、ヨウ分からんけど、とりあえず npx 経由で先にすすめるかな。。
できました。

>set NODE_ENV=production

>npx eleventy
[11ty] Writing _site/1/index.html from ./src/links.njk
[11ty] Writing _site/index.html from ./src/links.njk
[11ty] Writing _site/tw/index.html from ./src/links.njk
[11ty] Copied 2 files / Wrote 3 files in 0.12 seconds (v1.0.2)

なんか生成されとる。。
たとえばこんなの。

_site\tw\intex.html

<!DOCTYPE html>
<meta http-equiv=refresh content="0; url=https://twitter.com/kidjustino">

URLは、元のREADMEやサンプルに記述されているとおり。

src\links.json
{
  "/": "https://github.com/jstayton",
  "1": "https://fee.org/articles/the-use-of-knowledge-in-society/",
  "tw": "https://twitter.com/kidjustino"
}

よく分かってなかったけど、これで分かった。。
短縮URLに相当する場所に、静的ファイル置くので、対応ファイルを生成するためのツールなんやね。

応用(結局手で書く話)

逆に、そもそもこの生成ツールに依存する必要はないのだと理解できたので、任意の場所に任意のURL置くことに。
たとえば、こんなのにします。

r\abc12\index.html
<!DOCTYPE html>
<meta http-equiv=refresh content="0; url=onenote:///\\server\example\path\リンク先文書.one#section-id={UUID}&end">
<html>
リンク用のダミーページです
</html>

たとえばteamsの会議URLとかの伝達で困るようなときに有効かなと。。
但し、他アプリの起動リダイレクトとしての利用の場合(上記もそうですが)、本ページ自身は居残り(ブラウザに表示されつづける)なので、賢いとはいえない。
あくまで副作用を理解した上での、応急処置用ですね。。

仕組みを理解した上で、活用してみてください:-)

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1