ruby-on-rails-5 - 使用 wget 通过图像重定向制作站点的静态副本
问题描述
我想使用 wget 创建动态站点的静态副本。图像到达控制器,然后被重定向到它们的真实(过期)URL。我正在努力寻找适用于wget
. 我试过
wget \
--page-requisites --convert-links --max-redirect=10 \
http://activestorage-test.herokuapp.com
但图像路径未正确处理。
这是可行的吗?如果可行 - 怎么做?
背景
该站点是使用 Ruby on Rails 6 创建的。该站点上的图像是使用 Active Storage 上传的,因此浏览器会遇到 rails 控制器并在获取它们时被重定向。
例子
如果你能告诉我一种wget
用来获取静态副本的方法
activestorage-test.herokuapp.com
包括照片我的问题就解决了。重定向图像的随机图像名称是可以的,并且可能是必要的。
该应用程序可能需要一些时间来启动,因为它是 Heroku 的免费计划。
解决方案
这是使其工作的选项组合:
wget -mk http://activestorage-test.herokuapp.com
说明:
(取自这里)
-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 active storage dir 方案中存储为纯文本文件,例如:
├── rails
│ └── active_storage
│ └── representations
│ └── eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBLQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--192401464645b8679e8fc4b8b8e7423923a4404b
│ └── eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9MY21
该答案基于@Davebra 的评论,但删除了与问题无关的所有选项。
推荐阅读
- symfony - 使用 Sonata Admin 进行用户/组/角色管理
- vbscript - vbscript 不会正确执行“如果”
- selenium - 如何在 Tosca 中再次使用随机表达式?
- ansible - 如何强制 Ansible 中的变量只有 3 个字符或只有数字?
- swiftui - SwiftUI 初始化将存储在 UserDefaults 中的变量
- sql - 如何在没有不符合条件的重复项的情况下进行 JOIN?
- javascript - 如何将对象添加到现有的对象数组
- python - 与熊猫外部合并时出现重复问题
- pyqt - 使用 QTextEdit.clear() 时,PyQt6 无法为位于不同线程中的父级创建子级
- java - Android Studio 如何从 WallpaperManager 获取 Intent 服务