hugoにAmazonアソシエイトのリンクを表示するのに、ikemo3/hugo-amazon-jpというコンポーネントを使っています。
が、書籍の情報を貼るたびに毎回ショートコードを書くのが面倒だったので、Amazonの書籍ページからショートコードを生成するブックマークレットを作りました。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript: (function() { | |
var name = document.getElementById("productTitle").textContent; | |
var url = document.URL | |
var asin = url.match(/\d{10}/)[0]; | |
var title = window.prompt( | |
'for hugo-amazon-jp', '# {{< amazon category="book" key="' + name + '" >}}\n"' + name + '":\nasin: "' + asin + '"\ntitle: "' + name +'"' | |
); | |
})(); |
細かい注意点は以下です。
- 書籍データを書くyamlのファイル名がbook.yamlだとして作成しています。別のファイル名の場合は「book」のところを書き換えてください。
- #付きのコメントのところに、実際の記事に貼るショートコードを書いてあります。yamlに書籍データを貼り付けしたあと、ショートコード部分を再度コピペすることで記事に書籍へのリンクが貼れます。
出力されるコードのサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# {{< amazon category="book" key="業務デザインの発想法 ~「仕組み」と「仕掛け」で最高のオペレーションを創る" >}} | |
"業務デザインの発想法 ~「仕組み」と「仕掛け」で最高のオペレーションを創る": | |
asin: "4297104369" | |
title: "業務デザインの発想法 ~「仕組み」と「仕掛け」で最高のオペレーションを創る" |