![¿Cómo crear directorios que contengan index.html con wget --recursive?](https://rvso.com/image/97239/%C2%BFC%C3%B3mo%20crear%20directorios%20que%20contengan%20index.html%20con%20wget%20--recursive%3F.png)
Estoy bastante contento de cómo wget -r
funciona y descarga las cosas.
He configurado un servidor localhost que sirve a un sitio web y las páginas se ven así:
http://localhost:8080/
http://localhost:8080/foo
http://localhost:8080/bar
http://localhost:8080/blog/
http://localhost:8080/blog/1-and-here-the-slug
Cuando lo uso wget -r localhost:8080
crea la siguiente estructura:
.
├── static-files
│ └── ...
├── bar
├── blog
│ └── 1-and-here-the-slug
├── foo
└── index.html
bar
y foo
son 1-and-here-the-slug
archivos. Quiero que sean directorios con un solo archivo, con nombre index.html
y que aún no rompan las rutas a los recursos (CSS, JS, etc.).
Espero algo como esto:
.
├── 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
¿Cómo puedo hacer eso?
Respuesta1
http://localhost:8080/blog/1-and-here-the-slug
bar, foo y 1-and-here-the-slug son archivos. Quiero que sean directorios con un solo archivo, llamado index.html y que aún no rompan las rutas a los recursos (CSS, JS, etc.).
├── blog
│ └── 1-and-here-the-slug
│ └── index.html
Cuando accede http://localhost:8080/blog/1-and-here-the-slug
al directorio actual es blog
, si cambia el nombre de esa página a blog/1-and-here-the-slug/index.html
, su nuevo directorio actual sería blog/1-and-here-the-slug
. Por lo tanto, romperá las rutas relativas dentro del recurso (CSS, JS), si las hay. Yno hay manera de resolver esta pregunta sin modificar el HTML interno de los archivos.
Lo mejor que puedes hacer es cambiar el nombre de los archivos sin ninguna extensión para que tengan la extensión html.
├── blog
│ └── 1-and-here-the-slug.html
- Manteniendo el mismo directorio, puedes usar el
rename
comando de forma recursiva:
Ex:
find tmp -type f ! -name '*.*' | rename -nv 's/(.*)/$1.html/'
- Puede crear nuevos directorios, pero esto rompería los recursos relativos, si los hubiera.
Ex:
find tmp -type f ! -name '*.*' | while read file; do
mv $file $file.tmp;
mkdir $file;
mv $file.tmp $file/index.html;
done
Puedes jugar insertando la <base href="">
etiqueta en el archivo para especificar la buena ruta a los recursos, pero esto supondrá un trabajo muy duro y costoso.
- **O mejor, use el
-E
parámetro wget
EDITAR: leer wget
la página de manual te ofrece dos opciones maravillosas
-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.