离线 HTML 模板

发布于 2024-08-19 23:52:30 字数 536 浏览 7 评论 0原文

我正在设计一个没有动态内容的简单网站,我希望它是轻量级和可移植的 - 不需要或不想要 PHP 或其他服务器端脚本。我遇到了一个我之前已经问过几次的问题。

我希望能够编写一次常见元素(头部、脚部、导航),并仅使用内容编写网站上的各个页面,然后运行这个神秘的实用程序将所有内容编译成一组准备上传的 HTML 文件。页面可能会这样编写:

Title: Our Services
Top Navigation: Yes
Scripts: jquery, lightbox

<p>
    Example, Inc. offers a wide range of…

如果引擎还具有允许我在每个页面中包含或排除元素(如上面的顶部导航)的逻辑,并自动执行诸如标记当前页面之类的任务,那就太好了导航栏中的页面:

<a href="/services"{page == 'services' ? ' class="current"' : ""}>Services</a>

有这样的引擎吗?

I'm designing a simple website with no dynamic content that I want to be light and portable — no PHP or other server-side scripting needed, or wanted. I'm running into a question that I've had a few times before.

I'd love to be able to write common elements (head, foot, navigation) once and write the individual pages on the site with content only, then run this mysterious utility to compile everything it into a set of HTML files ready for uploading. A page might be written like this:

Title: Our Services
Top Navigation: Yes
Scripts: jquery, lightbox

<p>
    Example, Inc. offers a wide range of…

It'd be great if the engine also had logic that lets me include or exclude elements (like Top Navigation above) from each page, and automate tasks like labelling the current page in the navbar:

<a href="/services"{page == 'services' ? ' class="current"' : ""}>Services</a>

Are there any engines out there like this?

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

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

发布评论

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

评论(5

烟沫凡尘 2024-08-26 23:52:30

为此,我会直接前往 Template-Toolkit 。它附带了用于构建静态站点的 ttree 实用程序。

您可以使用以下方式处理问题的最后部分:

[% 
    INCLUDE 'navbar.tt' 
    page = 'services'
%]

I'd head directly towards Template-Toolkit for this. It comes with the ttree utility for building a static site.

You can handle the last part of your question with something like:

[% 
    INCLUDE 'navbar.tt' 
    page = 'services'
%]
猫九 2024-08-26 23:52:30

老实说,这就是 PHP 之类的东西派上用场的地方......包含常见元素

选项 1:使用一种语言并享受它。

选项 2:使用该语言创建网站...然后将爬虫指向您的网站以抓取生成的“静态”内容。例如 WinHTTPTrack

To be honest, this is where things like PHP come in handy... to include common elements

Option 1: Use a language and enjoy it.

Option 2: Use the language to make the site... but then point a crawler at your site to grab the generated "static" content. e.g. WinHTTPTrack

深者入戏 2024-08-26 23:52:30

Webby 在这方面非常出色。

另一个不错的选择是 Jekyll

Webby is fantastic for exactly this.

Another great option is Jekyll.

栖迟 2024-08-26 23:52:30

如果非免费工具适合您,Adobe Dreamweaver 的模板可以满足您的需要。

基本上,您创建一个模板页面,在其中定义哪些部分是可编辑的,然后根据该模板创建所有页面。如果您更改模板并保存它,所有关联的页面都会更新。

模板系统还能够定义默认属性并在特定页面中更改它们。您可以使用它来标记当前页面,但恕我直言,几行 jquery 代码会更好。

Adobe Dreamweaver's Templates do what you need if a non free tool is fine for you.

Basically you create a Template page where you define which parts are editable, then you create all your pages based on the template. If you change the template and save it all the associated pages are updates.

The templating system also has the ability to define default attributes and change them in a specific page. You can use this for labeling the current page, though for this IMHO a couple of lines of jquery code are much better.

挽你眉间 2024-08-26 23:52:30

您可以用您熟悉的任何语言编写一个输出静态 html 文件的程序。您可以有一个基本结构,然后对于定制的内容,您可以从单独的文件中包含它。

You could write a program in any language you are familiar with that outputs static html files. You could have a basic structure and then for the customized stuff, you include it from a separate file.

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