Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
静的WEBサイトをSPA化するワンライナー
Search
amanoese
December 24, 2018
Technology
160
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
静的WEBサイトをSPA化するワンライナー
第39回シェル芸勉強会の大阪サテライトLT (2018/12/24)で発表した内容になります。
amanoese
December 24, 2018
More Decks by amanoese
See All by amanoese
魔術式シェル芸
amanoese
0
1.3k
シェル芸でなれるVTuber!
amanoese
0
970
Technopop shell-gei(テクノポップシェル芸)
amanoese
0
570
Alexaアカウントリンクの認証と申請で躓いた話
amanoese
0
110
シェル芸のおかげでUnicodeに怯えず楽しめるようになった話
amanoese
0
270
AlexaにSSMLで音声記号(IPA) 使って喋らせたかった
amanoese
0
530
VUIでシェル芸を実行できるようにしてみた
amanoese
0
2.4k
インタラクティブなシェル芸実行コマンド作った感想
amanoese
0
210
Other Decks in Technology
See All in Technology
SREでアラート疲れを 解決しよう!
kairim0
1
210
ミイダス株式会社 テックチームのご紹介 / MIIDAS Tech Team
miidas
0
160
データ品質を壊しながらSnowflakeのAIに分析させてみた
kawanago
0
530
OR学会2026年秋期大会_機械学習と数理最適化の融合による、配合レシピ最適化システム開発事例
brainpadpr
0
100
Claude Code本は、どのように執筆チームで書かれたか
oikon48
0
300
ハードウェアコンペでもAI駆動開発が進んでいる話
iotengineer22
0
360
使いこなすために知っておきたい Azure SRE Agent アンチパターン
torumakabe
2
410
FinTech 1-2 : Overview of FinTech
ks91
PRO
0
150
不可逆な意思決定を避けながら10億超の顧客データを AI Ready にするデータ基盤設計
baseballyama
1
160
しろおびから始める!ログ活用の第一歩
shumei_ito
0
490
今こそ知りたいAmplifyGen2
mkdev10
2
160
More Freedom on the Same Shared GPU Cluster: A Small Team’s Experience with vCluster
nttcom
0
140
Featured
See All Featured
Writing Fast Ruby
sferik
630
63k
Facilitating Awesome Meetings
lara
57
7.2k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
From π to Pie charts
rasagy
1
390
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
450
Paper Plane
katiecoart
PRO
4
54k
Building Applications with DynamoDB
mza
96
7.2k
Chasing Engaging Ingredients in Design
codingconduct
0
340
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
260
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
Fireside Chat
paigeccino
43
4.1k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
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