![wget --recursive를 사용하여 index.html이 포함된 디렉토리를 만드는 방법은 무엇입니까?](https://rvso.com/image/97239/wget%20--recursive%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20index.html%EC%9D%B4%20%ED%8F%AC%ED%95%A8%EB%90%9C%20%EB%94%94%EB%A0%89%ED%86%A0%EB%A6%AC%EB%A5%BC%20%EB%A7%8C%EB%93%9C%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F.png)
나는 어떻게 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
, foo
및 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
- 동일한 디렉터리를 유지하면서 명령을 재귀적으로 사용할 수 있습니다
rename
.
전:
find tmp -type f ! -name '*.*' | rename -nv 's/(.*)/$1.html/'
- 새 디렉터리를 만들 수 있지만 이로 인해 관련 리소스가 손상될 수 있습니다.
전:
find tmp -type f ! -name '*.*' | while read file; do
mv $file $file.tmp;
mkdir $file;
mv $file.tmp $file/index.html;
done
파일에 태그를 삽입하여 <base href="">
리소스에 대한 올바른 경로를 지정할 수 있지만 이는 비용이 많이 드는 작업이 많이 소요됩니다.
- **또는
-E
wget 매개변수를 사용하는 것이 더 좋습니다.
편집: 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.