¿Cómo crear directorios que contengan index.html con wget --recursive?

¿Cómo crear directorios que contengan index.html con wget --recursive?

Estoy bastante contento de cómo wget -rfunciona 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:8080crea la siguiente estructura:

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

bary foo son 1-and-here-the-slugarchivos. Quiero que sean directorios con un solo archivo, con nombre index.htmly 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-slugal 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
  1. Manteniendo el mismo directorio, puedes usar el renamecomando de forma recursiva:

Ex:

  find tmp -type f ! -name '*.*' | rename -nv 's/(.*)/$1.html/'
  1. 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.

  1. **O mejor, use el -Eparámetro wget

EDITAR: leer wgetla 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.

información relacionada