wget --recursive를 사용하여 index.html이 포함된 디렉토리를 만드는 방법은 무엇입니까?

wget --recursive를 사용하여 index.html이 포함된 디렉토리를 만드는 방법은 무엇입니까?

wget -r이 기능이 작동하고 다운로드되는 방식 에 만족합니다 .

웹 사이트를 제공하는 로컬 호스트 서버를 설정했는데 페이지는 다음과 같습니다.

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

bar, foo1-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매뉴얼 페이지를 읽으면 두 가지 좋은 옵션이 제공됩니다.

  -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.

관련 정보