There are 4 distinct URL types;
- Absolute
http://www.example.com/images/icons.png
- Document-Relative
../images/icons.png
- Root-Relative
/images/icons.png
- Protocol-Relative
//www.example.com/images/icons.png
I have a large static file site (html, css, js) which is built with Jigsaw . This framework takes PHP templates and compiles them into static HTML. I am also using Gulp tasks to compile assets (sass, js..etc).
Using Jigsaw's build process I can either have the site built with full Absolute paths/urls (http://example.com/path-to/page
) or Root-Relative (/path-to/page
).
This is great but now the client wants the site to use Document-Relative as they are now hosting the site in a subdirectory with a URL pointing to that subdirectory.
E.g.http://example.com
would point tohttp://xx.server.com/hosted-files/directory
My issue is that Jigsaw doesn't allow for Document-Relative URLs. Is there a gulp/node script I can use to convert all references (image sources, links, css paths..etc)? Or is there another solution (e.g. using .htacccess)?
TLDR;
I need to replace any Absolute or Root-Relative references in multiple HTML files and directories with Document-Relative paths and URLs. Or is there another solution (e.g. using .htacccess)?
2条答案
按热度按时间gz5pxeao1#
我已经设法解决了我自己的问题,我觉得这是一个“黑客”修复。
我基本上已经创建了一个自定义的gulp插件,用文档相对路径替换URL/路径等。
gulpfile.js-
relative-urls
任务在所有其他任务完成后运行。./tasks/文档相关.js-插件
这基本上打开了我的build文件夹中的所有
.html
文件,计算每个文件的路径深度(/folder1/folder2/index.html),并将url
(http://localhost:8000)的任何示例替换为../
,重复计算出的路径数。jbose2ul2#
节点具有path.relative。
url
和directory
的来源。*