wget 将指纹从 ?进入%3F

问题描述 投票:0回答:1

我想镜像我的 cms 驱动网站以创建纯 html 静态版本。使用

-k
选项 (
--convert-links
) 启用本地查看。

但是,wget 在其 html 文件中将问号

?
转换为百分比编码的 ascii
%3F

wget -m -nH -np -k -E --restrict-file-names=unix,nocontrol https://localhost/mysite

示例:

从来源输入 https://localhost/mysite:

<link href="/dist/css/main.css?fp=12345" type="text/css" rel="stylesheet">
<a href="/contact">Contact</a>

wget 的预期输出

<link href="/dist/css/main.css?fp=12345" type="text/css" rel="stylesheet">
<a href="/contact.html">Contact</a>

wget 的实际输出

<link href="/dist/css/main.css%3Ffp=12345.css" type="text/css" rel="stylesheet">
<a href="/contact.html">Contact</a>

请注意,联系链接现在特意带有

.html
后缀 (
-E
)。这是对的。 对于此用例,可以忽略向指纹添加
.css
后缀。

请注意,指纹

?
会转换为
%3F
,这会破坏本地查看。

如何镜像我的网站并保持指纹完好无损?

wget static-site static-site-generation
1个回答
0
投票

一个可能的解决方案是使用 sed shell 脚本进行搜索替换:

#! /bin/bash

# replaces all occurences of string %Ffp with ?fp in *.html files
find "/var/www/mysite" -type f -name "*.html" -exec sed -i -s -r 's/%3Ffp/?fp/g' {} +

小心路径,此命令会查看 /var/www/mysite 及其子文件夹中的所有 html 文件。

© www.soinside.com 2019 - 2024. All rights reserved.