【问题标题】:How can I have Wintersmith generate a static site with a blog in a subdirectory?如何让 Wintersmith 在子目录中生成带有博客的静态站点?
【发布时间】:2014-11-08 11:22:10
【问题描述】:

我正在研究 Wintersmith 化我的网站,该网站目前是手写的。我有几个页面:index.htmlprojects.htmlgpg.html 等。我想要一个blog/ 子目录,以便最终站点看起来像这样:

.
|- index.html
|- gpg.html
|- project.html
|- blog/
|  |- look-a-new-wintersmith-blog.md
|  |- monkeys-are-really-cool.md

这可能吗?我搜索并查看了 Wintersmith 文档(甚至是由 Wintersmith 提供支持的特色站点),但一无所获。似乎唯一的方法是拥有两个 Wintersmith 实例或其他东西,但似乎必须有更好的方法。

【问题讨论】:

    标签: static-site wintersmith


    【解决方案1】:

    您应该通过以下方式获得所需的结果:

    ├── config.json               <- site configuration
    ├── contents
    │   ├── index.html            <- these will just be outputted as-is
    │   ├── gpg.html
    │   ├── project.html
    │   ├── blog                  <– each article has its own directory
    │   │   ├── index.json        <- this is your blog index at /blog/index.html
    │   │   ├── look-a-new-wintersmith-blog
    │   │   │   └── index.md
    │   │   └── monkeys-are-really-cool
    │   │       └── index.md
    │   ├── authors               <- author metadata, check author.jade
    │   │   └── the-wintersmith.json
    │   ├── css
    │   │   └── main.css
    │   └── feed.json
    ├── plugins
    │   └── paginator.coffee      <- paginator plugin
    ├── templates
    │   ├── archive.jade
    │   ├── article.jade
    │   ├── author.jade
    │   ├── feed.jade
    │   ├── index.jade
    │   └── layout.jade
    └── views
        └── articles.coffee       <- view that lists articles
    

    index.json 只是一个重命名并移动了archive.json 以提供/blog/index.html URL。如果您想要默认 Wintersmith 索引而不是存档布局,请编辑文件以使用 index.jade 布局而不是 archive.jade

    如果您将当前的 HTML 文件更改为 Markdown 并将它们放在同一个位置,那么它们将像您的博客文章一样以 HTML 格式输出。

    您可能还想在 article 布局中添加某种导航菜单。

    编辑:要创建静态页面,请在contents 中创建类似于以下内容的 Markdown 文件:

    ---
    title: GPG
    author: baker
    date: 2014-03-23
    template: article.jade
    ---
    
    Content
    

    如果您将此文件命名为gpg.md,则应该可以通过http://localhost:8080/gpg.html 访问它。因为我们使用了article.jade 模板,所以它需要一个author 和一个date 字段来保证完整性(它可以在没有作者的情况下工作,但它仍然会包含“Written by”而没有作者),但您可以制作一个自定义模板不使用这些字段。

    【讨论】:

    • 这看起来不错,但并不是我想要的。如果您这样做以便我可以使用模板系统呈现index.htmlgpg.html 等,我会接受这个答案 - 尽管我已经停止使用 Wintersmith 来生成静态站点,所以我假设很好信仰。
    • 我认为您要问的是默认的 about.md 文件中显示的内容,该文件由默认的 Wintersmith 站点生成;你给它一个markdown文件(gpg.md),它会生成一个静态HTML页面(gpg.html)。如果需要,您可以在元数据块中为其提供不同的布局等。
    • 我没有看到你说的文件,除了页脚文件(定义在contents/about.md)。
    • 抱歉,我忘记了 Wintersmith 默认将其作为页脚。尽管为简单起见使用了默认模板,但使用更通用的解决方案更新了我的答案。
    猜你喜欢
    • 2013-10-02
    • 2015-09-09
    • 2020-03-07
    • 2016-03-01
    • 1970-01-01
    • 2011-07-06
    • 1970-01-01
    • 2016-06-02
    • 2022-10-15
    相关资源
    最近更新 更多