Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
静的WEBサイトをSPA化するワンライナー
Search
amanoese
December 24, 2018
Technology
0
120
静的WEBサイトをSPA化するワンライナー
第39回シェル芸勉強会の大阪サテライトLT (2018/12/24)で発表した内容になります。
amanoese
December 24, 2018
Tweet
Share
More Decks by amanoese
See All by amanoese
魔術式シェル芸
amanoese
0
1.3k
シェル芸でなれるVTuber!
amanoese
0
940
Technopop shell-gei(テクノポップシェル芸)
amanoese
0
550
Alexaアカウントリンクの認証と申請で躓いた話
amanoese
0
89
シェル芸のおかげでUnicodeに怯えず楽しめるようになった話
amanoese
0
230
AlexaにSSMLで音声記号(IPA) 使って喋らせたかった
amanoese
0
500
VUIでシェル芸を実行できるようにしてみた
amanoese
0
2.2k
インタラクティブなシェル芸実行コマンド作った感想
amanoese
0
190
Other Decks in Technology
See All in Technology
Introduction to Sansan Meishi Maker Development Engineer
sansan33
PRO
0
330
Eight Engineering Unit 紹介資料
sansan33
PRO
0
6.1k
Everything As Code
yosuke_ai
0
480
純粋なイミュータブルモデルを設計してからイベントソーシングと組み合わせるDeciderの実践方法の紹介 /Introducing Decider Pattern with Event Sourcing
tomohisa
1
190
AIエージェントを5分で一気におさらい!AIエージェント「構築」元年に備えよう
yakumo
1
130
名刺メーカーDevグループ 紹介資料
sansan33
PRO
0
1k
AI時代のアジャイルチームを目指して ー スクラムというコンフォートゾーンからの脱却 ー / Toward Agile Teams in the Age of AI
takaking22
9
2.5k
Master Dataグループ紹介資料
sansan33
PRO
1
4.2k
[Data & AI Summit '25 Fall] AIでデータ活用を進化させる!Google Cloudで作るデータ活用の未来
kirimaru
0
4.2k
ESXi のAIOps だ!2025冬
unnowataru
0
470
2025-12-27 Claude CodeでPRレビュー対応を効率化する@機械学習社会実装勉強会第54回
nakamasato
4
1.4k
Authlete で実装する MCP OAuth 認可サーバー #CIMD の実装を添えて
watahani
0
380
Featured
See All Featured
sira's awesome portfolio website redesign presentation
elsirapls
0
100
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.3k
The untapped power of vector embeddings
frankvandijk
1
1.5k
Raft: Consensus for Rubyists
vanstee
141
7.3k
Testing 201, or: Great Expectations
jmmastey
46
7.8k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.2k
WENDY [Excerpt]
tessaabrams
9
35k
How to Ace a Technical Interview
jacobian
281
24k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
120
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
990
HDC tutorial
michielstock
1
290
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.3k
Transcript
静的WEBサイトをSPA化する ワンライナー
自己紹介 RustとElmに憧れてる自称ウェッブ系エンジニア javascriptとシェル芸が好き 仕事はIBM Cloudのなかでふるすたっくに頑張るひと Spring BootとVue.js使ってAI系の案件をフワッとやってま す。 最近Elmの勉強を始めました。 taka@SIではたらくフレンズ
@amanoese
SPAとは?
SPAとは? ようは1ファイルにすればよい(横暴)
なぜ? 引き継ぎ資料の作成中 先輩「すべてのドキュメントを散らばらず、1つのファイルで作って」 ↓ 自分で作れよ gitbookでpdfにする? いやフォーマットあれだし結局サーバサイドが必要? ↓ シェル芸でなんとかならないか?
どうするか gitbookはbuildすると、 _book/にhtmlやcss、jsなどの成果物を出力する。
どうするか ファイルはデータURIにすると、文字列として扱えるようになる
どうするか このファイルたちをbase64化してhtmlファイルに埋め込む
どうするか あまり知られてない?ですが、 htmlファイルもdataURIとして扱えます。
どうするか html以外のコンテンツをデータURI (base64)化 ↓ htmlのリンクをすべて差し替え ↓ データURI化されたコンテンツを埋め込まれたhtmlをデータURI化 ↓ データURIなhtmlを1つのファイルに埋め込みコントロールする javascript+htmlを書けばOK
javascriptの復習 html , body ,head タグは書かなくても良い。。。 書かないとかってにbodyに入ります。またhtml,head,bodyは暗黙で生成されます。
None
javascriptの復習 ‘()’中括弧を使うと’;’を書かなくずに連続した処理が短くかける。
javascriptの復習 コンソールからは使えるけど、コンソール以外からは使えない
javascriptの復習 汚染や間違えたメソッドの使い方は気にしない
頑張って書く
これでできる。。。? printf '<html><iframe src="" frameborder="0" width="100%%" height="100%%"></iframe><script>(f=(a,d=document.all[3])=>(d.onload=_=>[... frames[0].document.querySelectorAll("a")].map(x=>x.onclick=_=>f(x.href)),d.src ="data:text/html;base64,"+({%s})[new URL(a,"http://_/").pathname]))("index.html")</script></html>'
$(find -type f | grep html$ | xargs -L1 -i bash -c "echo \\\"\$(echo {}| cut -c 2-)\\\":\\\"\$(base64 -w0 <(sed -f <(find -type f | egrep -v '(html|md)\$' | awk '{print length(), \$0}' | sort -nr | cut -d ' ' -f2- | cut -c3- | xargs -L1 -I@ bash -c 'echo s\|[.\/]*@\|data:\$(echo @ | sed -e s\/.*css$\/text\\\/css\/ -e s\/.*js$\/application\\\/javascript\/ -e s\#@\#\# | grep . || file @ -ib)\;base64,\$(base64 -w0 @)\|g') {}))\\\"," | tr -d \\n ) | tee spa.html
これでできる。。。?
データURI https://developer.mozilla.org/ja/docs/data_URIs#Encoding_data_into_base64_format
回避策 form要素の中でform要素を展開するjavascriptを埋め込むjavascript(再帰的)を書 けば多分いける。。。 ただ、ソースがもう読めないので諦めたい。。。。
回避策2 Electronに突っ込めんでexe化すれば終わります。 「ドキュメント.exe」になる闇が残りますが。。。
None