ブログ作成にこれ一本。
BlogEditor
ブログを書くためのTemplaterスクリプトです。
カーソル行がURLアドレスの場合はブログカードを作る。 それ以外だったらSafariで検索する。 空行だったらはてなブログ・アプリに転送する。
この三つの機能をこのスクリプトで賄います。
変更点
カーソル行がTwitterのアドレスだったらツィートになります。 twitframe.comという埋め込みサービスを経由しています。 縦サイズが決められないのが問題だけど。
<%* e = app.workspace.activeLeaf.view.editor; p = e.getCursor(); s = e.getLine(p.line); if(/^http/.test(s)) { switch(true){ case /youtube\.com/.test(s): id = s.split("v=")[1].split("&")[0]; s = "<iframe width='350px' height='200px' src=\"http://www.youtube.com/embed/" + id + "\" frameborder=0></iframe>\n"; break; case /(\.jpg|\.png|\.gif)/.test(s): s = "<img width='400px' src='" + s + "'>\n"; break; case /gyazo\.com/.test(s): s = "<img width='400px' src='" + s + "/raw'>\n"; break; case /twitter\.com/.test(s): s = s.replace(/mobile\./, "www"); s = "<iframe border=0 frameborder=0 width='400px' height='600px' src='https://twitframe.com/show?url=" + s + "'></iframe>\n"; break; default: s = "<iframe src='https://hatenablog.com/embed?url=" + s + "' width='350px' frameborder='0' scrolling='no'></iframe>\n"; } e.setLine(p.line, s); }else{ if(s){ open("https://google.co.jp/search?q=" + encodeURIComponent(s)); }else{ p = tp.file.content.split("\n"); a = p.shift(); b = p.join("\n"); url = "hatenablog:///new?title=" + encodeURIComponent(a) + "&body=" + encodeURIComponent(b); open(url); } } %>
使い方
ツィートの共有ボタンで「ツィートのリンクをコピー」を選んでください。 それをObsidianに貼り付けBlogEditorを実行すると、下記のように埋め込みます。
ピンクムーンは「桜月」という感じかな。
まとめ
これってAPIを使ってないのだろうか。