
Estou muito feliz como wget -r
funciona e baixa as coisas.
Eu configurei um servidor localhost que atende um site e as páginas ficam assim:
http://localhost:8080/
http://localhost:8080/foo
http://localhost:8080/bar
http://localhost:8080/blog/
http://localhost:8080/blog/1-and-here-the-slug
Quando eu uso wget -r localhost:8080
ele cria a seguinte estrutura:
.
├── static-files
│ └── ...
├── bar
├── blog
│ └── 1-and-here-the-slug
├── foo
└── index.html
bar
, foo
e 1-and-here-the-slug
são arquivos. Quero que sejam diretórios com um único arquivo, nomeados index.html
e ainda sem quebrar os caminhos para os recursos (CSS, JS etc).
Espero algo assim:
.
├── 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
Como eu posso fazer isso?
Responder1
http://localhost:8080/blog/1-and-here-the-slug
bar, foo e 1-and-here-the-slug são arquivos. Quero que sejam diretórios com um único arquivo, denominado index.html e ainda sem quebrar os caminhos para os recursos (CSS, JS etc).
├── blog
│ └── 1-and-here-the-slug
│ └── index.html
Quando você acessa http://localhost:8080/blog/1-and-here-the-slug
o diretório atual é blog
, se você renomear essa página para ser blog/1-and-here-the-slug/index.html
, seu novo diretório atual seria blog/1-and-here-the-slug
. Então você quebrará os caminhos relativos dentro do recurso (CSS, JS), se houver. Enão há como resolver esta questão sem modificar o HTML interno dos arquivos.
A melhor coisa que você pode fazer é renomear arquivos sem qualquer extensão para ter a extensão html.
├── blog
│ └── 1-and-here-the-slug.html
- Mantendo o mesmo diretório, você pode usar o
rename
comando recursivamente:
Ex:
find tmp -type f ! -name '*.*' | rename -nv 's/(.*)/$1.html/'
- Você pode criar novos diretórios, mas isso quebraria os recursos relativos, se houver
Ex:
find tmp -type f ! -name '*.*' | while read file; do
mv $file $file.tmp;
mkdir $file;
mv $file.tmp $file/index.html;
done
Você pode brincar inserindo a <base href="">
tag no arquivo para especificar o bom caminho para os recursos, mas isso será muito trabalhoso e caro
- **Ou melhor, use o
-E
parâmetro wget
EDIT: ler wget
a página de manual oferece duas opções maravilhosas
-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.