使用 wget 制作带有图像重定向的站点的静态副本

Use wget to make static copy of site with image redirects

我想使用 wget 创建动态站点的静态副本。图像命中控制器,然后被重定向到它们的真实(过期)URL。我正在努力寻找 wget 的工作命令行选项。我试过了

wget \
--page-requisites --convert-links --max-redirect=10 \
http://activestorage-test.herokuapp.com

但是图像路径没有正确处理。

这可行吗?如果可行,怎么做?

背景

该站点是在 Rails 6 上使用 Ruby 创建的。该站点上的图像是使用 Active Storage 上传的,因此浏览器会访问 rails 控制器并在 GETting 时被重定向他们。

例子

如果你能告诉我使用wget获取

静态副本的方法

activestorage-test.herokuapp.com

包括照片我的问题解决了。重定向图像的随机图像名称是可以的,而且可能是必要的。

应用程序可能需要一些时间来启动,因为它是 Heroku 的免费计划。

这是使它起作用的选项组合:

wget -mk http://activestorage-test.herokuapp.com

解释:

(摘自here

-m
--mirror
    Turn on options suitable for mirroring.  This option turns on recursion and time-stamping, sets
    infinite recursion depth and keeps FTP directory listings.  It is currently equivalent to -r -N -l
    inf --no-remove-listing.

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

这将使图像存储为 rails 活动存储目录方案中的纯文本文件,例如:

├── rails
│   └── active_storage
│       └── representations
│           └── eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBLQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--192401464645b8679e8fc4b8b8e7423923a4404b
│               └── eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9MY21

此答案基于@Davebra 的评论,但删除了与问题无关的所有选项。