HTML5 Boilerplate Build 脚本 - 子文件夹中的 HTML 以及 CSS/JS 问题的相关链接

发布于 2024-12-06 15:57:32 字数 808 浏览 0 评论 0原文

我的项目使用 HTML5Boilerplate 并包含带有 HTML 文件的子目录,这些文件引用主根文件夹中的 /js 和 css/ 。

例子: /article/xxx/index.html /article/yyy/index.html

这些 .html 文件具有到根文件夹中 css/js 文件的相对路径 href/src。

<link rel="stylesheet" href="../../css/style.css" />
<script src="../../js/plugins.js"></script>
<script src="../../js/script.js"></script>

我试图让构建脚本识别子目录中的这些文件,并相应地替换连接/缩小的 JS 和 CSS 文件的路径,我尝试将其添加到 project.properties 上的 file.pages 属性中,

file.pages =  index.html, article/xxx/*.html, article/xxx/*.html

但没有骰子,CSS /JS 路径被替换,就像文件位于根文件夹中一样,如下所示:

<link rel=stylesheet href='css/7d3586f292b65c896ef495e2e8ef042901d7c2e2.css'>

这显然不起作用。 如果有人知道解决方法/修改,或者这可能只是一个不行的话,我将非常感激?

预先感谢任何帮助:D

My project is using HTML5Boilerplate and contains subdirectories with HTML files that reference /js and css/ in the main root folders.

Example:
/article/xxx/index.html
/article/yyy/index.html

These .html files have relative path href/src to the css/js files in the root folder.

<link rel="stylesheet" href="../../css/style.css" />
<script src="../../js/plugins.js"></script>
<script src="../../js/script.js"></script>

I'm trying to have the build script recognise these files in the subdirectories and replace the paths accordingly to the concatenated/minified JS and CSS files and I tried adding this to the file.pages property on project.properties

file.pages =  index.html, article/xxx/*.html, article/xxx/*.html

But no dice, the CSS/JS paths get replaced as if the files are in the root folder, like so:

<link rel=stylesheet href='css/7d3586f292b65c896ef495e2e8ef042901d7c2e2.css'>

Which doesn't work evidently.
Would be really grateful if anyone knows a workaround/modification for this or if this might just plain be a no-go?

Thanks in advance to any help :D

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

娇女薄笑 2024-12-13 15:57:32

也许您可以尝试使用

file.pages =  index.html, article/**/*.html

glob 模式可能会更好地符合构建脚本。我刚刚在一个空项目上测试了这个,index.html 文件位于 article/fold1/article/fold2/ 下,两者的相对路径与我

得到的

<link rel=stylesheet href='../../css/b218ab4.css'>

相同,它可能会让您在更新文章文件夹下的 html 文件时省去一些麻烦,**/*.html 模式将捕获这些目录中的所有 html 文件。

Maybe you could try to use

file.pages =  index.html, article/**/*.html

the glob pattern may comply better with the build script. I just tested this on an empty project, with index.html files under article/fold1/ and article/fold2/, both with the same relative path than yours

I get

<link rel=stylesheet href='../../css/b218ab4.css'>

also, it might save you some headache to update html files under your articles folder, the **/*.html pattern will catch up any html files within these directories.

冰雪之触 2024-12-13 15:57:32

您需要编辑 build.xml 脚本。在第 630 行左右,使用正则表达式替换对串联版本的 js 和 css 引用,但它不考虑子目录。我将其中的行更改为:

<echo message="Update the HTML to reference our concatenated script file: ${scripts.js}"/>
<!-- style.css replacement handled as a replacetoken above -->
<replaceregexp match="<!-- scripts concatenated [\d\w\s\W]*?src="([\d\w\s\W]*?)js/[\d\w\s\W]*?!-- end ((scripts)|(concatenated and minified scripts))-->" replace="<script defer src='\1${scripts.js}\'></script>" flags="m">
  <fileset dir="${dir.intermediate}" includes="${page-files}"/>
</replaceregexp>
<!--[! use comments like this one to avoid having them get minified -->

<echo message="Updating the HTML with the new css filename: ${style.css}"/>

<replaceregexp match="<!-- CSS concatenated [\d\w\s\W]*?href="([\d\w\s\W]*?)css/[\d\w\s\W]*?!-- end CSS-->" replace="<link rel='stylesheet' href='\1${style.css}'>" flags="m">
  <fileset dir="${dir.intermediate}" includes="${page-files}"/>
</replaceregexp>

我想正则表达式可以更有效。

西蒙

You need to edit the build.xml script. Around line 630 a regex is used to replace the js and css references to the concatenated versions but it does not take account of subdirectories. I changed the lines there to:

<echo message="Update the HTML to reference our concatenated script file: ${scripts.js}"/>
<!-- style.css replacement handled as a replacetoken above -->
<replaceregexp match="<!-- scripts concatenated [\d\w\s\W]*?src="([\d\w\s\W]*?)js/[\d\w\s\W]*?!-- end ((scripts)|(concatenated and minified scripts))-->" replace="<script defer src='\1${scripts.js}\'></script>" flags="m">
  <fileset dir="${dir.intermediate}" includes="${page-files}"/>
</replaceregexp>
<!--[! use comments like this one to avoid having them get minified -->

<echo message="Updating the HTML with the new css filename: ${style.css}"/>

<replaceregexp match="<!-- CSS concatenated [\d\w\s\W]*?href="([\d\w\s\W]*?)css/[\d\w\s\W]*?!-- end CSS-->" replace="<link rel='stylesheet' href='\1${style.css}'>" flags="m">
  <fileset dir="${dir.intermediate}" includes="${page-files}"/>
</replaceregexp>

I imagine the regex can be more efficient.

Simon

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文