もた日記

くだらないことを真面目にやる

Linuxメモ : Rust製のmonolithでWebページをjs, css, 画像を含んだ1つのHTMLとして保存

monolith

github.com

Rust製のmonolithを使うとWebページをjs, css, 画像を含んだ1つのHTMLとして保存することができる。


インストール

README.mdのインストール方法によるとDocker版やソースコードのビルドでインストールできる(cargo install monolithだと初期バージョンがインストールされて使い物にならない)。

$ git clone https://github.com/Y2Z/monolith.git
$ cd monolith
$ make install

ヘルプメッセージ。

$ monolith --help
monolith 2.2.3
Sunshine <sunshine@uberspace.net>
Mahdi Robatipoor <mahdi.robatipoor@gmail.com>
Emmanuel Delaborde <th3rac25@gmail.com>
Emi Simpson <emi@alchemi.dev>
rhysd <lin90162@yahoo.co.jp>
CLI tool for saving web pages as a single HTML file

USAGE:
    monolith [FLAGS] [OPTIONS] <target>

FLAGS:
    -h, --help         Prints help information
    -k, --insecure     Allows invalid X.509 (TLS) certificates
    -I, --isolate      Cuts off document from the Internet
    -c, --no-css       Removes CSS
    -f, --no-frames    Removes frames and iframes
    -i, --no-images    Removes images
    -j, --no-js        Removes JavaScript
    -s, --silent       Suppresses verbosity
    -V, --version      Prints version information

OPTIONS:
    -o, --output <document.html>    Writes output to <file>
    -t, --timeout <60>              Adjusts network request timeout
    -u, --user-agent <Firefox>      Sets custom User-Agent string

ARGS:
    <target>    URL or file path


使い方

README.mdのUsageにあるように対象ページの後に-oオプションで出力ファイル名を指定すればよい。

$ monolith https://lyrics.github.io/db/P/Portishead/Dummy/Roads/ -o portishead-roads-lyrics.html

コマンドを実行すると以下のように順番にリソースをダウンロードしているのが確認できる(-sオプションで出力はオフにできる)。

$ monolith https://lyrics.github.io/db/P/Portishead/Dummy/Roads/ -o portishead-roads-lyrics.html
https://lyrics.github.io/db/P/Portishead/Dummy/Roads/
https://lyrics.github.io/favicon.ico
https://lyrics.github.io/s.css
https://lyrics.github.io/1.svg
https://lyrics.github.io/2.svg
https://lyrics.github.io/3.svg

処理が完了すると対象ページの見た目そのままのHTMLファイルが生成される。

f:id:wonder-wall:20200415231740p:plain


関連ツール

Chrome拡張機能版もあるようだ。

github.com