wget --recursiveを使用してindex.htmlを含むディレクトリを作成するには?

wget --recursiveを使用してindex.htmlを含むディレクトリを作成するには?

wget -rこの機能が機能してダウンロードされる方法に満足しています。

Webサイトを提供するローカルホストサーバーを設定しましたが、ページは次のとおりです。

http://localhost:8080/
http://localhost:8080/foo
http://localhost:8080/bar
http://localhost:8080/blog/
http://localhost:8080/blog/1-and-here-the-slug

使用すると、wget -r localhost:8080次の構造が生成されます。

.
├── static-files
│   └── ...
├── bar
├── blog
│   └── 1-and-here-the-slug
├── foo
└── index.html

barfoo および1-and-here-the-slugファイルです。私はそれらがindex.htmlリソース(CSS、JSなど)へのパスを中断することなく、名前付きの個々のファイルを含むディレクトリになりたいと思います。

私は次のように期待しています:

.
├── static-files
│   └── ...
├── bar
│   └── index.html
├── foo
│   └── index.html
├── blog
│   ├── index.html // <---------- Also I want this one here to show the blog
│   └── 1-and-here-the-slug
│       └── index.html
└── index.html

どうすればいいですか?

ベストアンサー1

http://localhost:8080/blog/1-and-here-the-slug

bar、foo、1-and-here-the-slug はファイルです。私はそれらがindex.htmlという単一のファイルを含むディレクトリであり、まだリソース(CSS、JSなど)へのパスを中断したくないと思います。

├── blog
│   └── 1-and-here-the-slug
│       └── index.html

http://localhost:8080/blog/1-and-here-the-slug現在のディレクトリにアクセスするときにblogページ名をに変更するとblog/1-and-here-the-slug/index.html、新しい現在のディレクトリはになりますblog/1-and-here-the-slug。したがって、リソース(CSS、JS)内に相対パスがある場合、これを中断します。そしてファイルの内部HTMLを変更せずにこの問題を解決する方法はありません。

最善の方法は、拡張子のないファイルの名前をhtml拡張子に変更することです。

├── blog
│   └── 1-and-here-the-slug.html
  1. 同じディレクトリを維持しながら、renameこのコマンドを再帰的に使用できます。

前任者:

  find tmp -type f ! -name '*.*' | rename -nv 's/(.*)/$1.html/'
  1. 新しいディレクトリを作成できますが、これにより関連リソース(存在する場合)が削除されます。

前任者:

  find tmp -type f ! -name '*.*' | while read file; do
       mv $file $file.tmp;
       mkdir $file;
       mv $file.tmp $file/index.html;
 done

<base href="">ファイルにタグを挿入してリソースへの良いパスを指定できますが、これは困難で高価な作業です。

  1. **またはより良い方法は-Ewgetパラメータを使用することです。

編集:wgetマニュアルページを読むと、2つの良いオプションが提供されます。

  -E
  --adjust-extension
       If a file of type application/xhtml+xml or text/html is downloaded
       and the URL does not end with the regexp \.[Hh][Tt][Mm][Ll]?, this option
       will cause the suffix .html to be appended to the local filename. 

  -k
   --convert-links
       After the download is complete, convert the links in the document to
       make them suitable for local viewing.  This affects not only the visible
       hyperlinks, but any part of the document that links to external content, 
       such as embedded images, links to style sheets, hyperlinks to non-
       HTML content, etc.

おすすめ記事