谈谈 Jamstack 的未来——加入我们

Entu SSG

14 stars
4 forks
2 issues
主页
https://ssg.entu.app
存储库
entu/ssg
语言
JavaScript
许可
MIT
模板
Pug、Markdown、Stylus

Entu SSG 是一个简单的 Pug、Markdown、Yaml 静态网站生成器,支持多种语言环境。

好处

  • 简单的 Pug(以前叫 Jade),Markdown、Yaml 静态网站生成器。
  • Pug 模板或 Markdown 生成静态 HTML 文件。
  • 使用 Yaml 文件将数据传递到模板。
  • 在文件名中使用语言标识符来生成特定语言内容和路径。
  • Stylus 文件生成网站 CSS。
  • 使用你最喜欢的工具/编辑器。
  • 自行托管在您的服务器上、Netlify 上、S3 上或其他地方。

安装与使用

  1. 下载 最新版本
  2. 运行
    ./build.js ./my-page/entu-ssg-config.yaml

配置

可以通过 Yaml 文件配置网站构建过程,其路径必须是 entu-ssg.js 的第一个参数。必需的参数为

  • locales - 要生成的语言环境文件夹的列表。可以将语言环境标识符放在文件名中(如 index.en.pug 或 data.et.yaml)以获得特定语言环境的内容。
  • defaultLocale - 如果设置,则此语言环境的页面路径将不会获得语言环境前缀(/en/about 将变成 /about)。
  • source - 源文件文件夹(相对于构建 config.yaml)。以下划线开头的文件夹将被忽略。
  • build - 放置已生成 HTML 的文件夹(相对于构建 config.yaml)。
  • assets - 包含静态资源(JS、图像等)的文件夹。
  • protectedFromCleanup - 如果使用 cleanup 参数运行 build.sh,则不会删除的路径列表。相对于 build 路径。
  • server.port - 在 localhost 上提供服务时使用的端口。
  • server.assets - 在 localhost 中提供页面时,该 URL 将映射到 assets 参数中指定的文件夹。
  • dev.aliases - 构建页面别名。
  • dev.paths - 要构建的(源)路径列表。相对于 source 路径。

示例生成配置文件

locales:
  - en
  - et
source: ./source
build: ./build
assets: ./assets
protectedFromCleanup:
  - assets
  - index.html
server:
  port: 4000
  assets: /assets/
dev:
  aliases: true
  paths:
    - test/page1
    - test/page2

内容

页面内容 - index.pug

页面内容由 **index.pug** 文件生成。所有其他文件都将被忽略,但您可以将这些文件用于 Pug include/extends。您可以在文件名中放置语言环境标识符(如 index.en.pug)以提供特定于语言环境的内容。

页面数据和配置 - data.yaml

若要将数据传递到 index.pug,请使用 **data.yaml** 文件。此数据以名为 self 的对象传递到 index.pug(若要从 data.yaml 中获取属性 text,请在 index.pug 中使用 self.text)。

您可以在文件名中放置语言环境标识符(如 data.en.yaml)以提供特定于语言环境的内容。

一些页面参数会改变 HTML 的生成方式。这些是

  • disabled - 如果为真,则不会生成页面,也不会将其加载到 self.otherLocalePaths 对象中。
  • path - 如果设置,它将覆盖基于文件夹的路径。
  • aliases - 路径别名的列表。将使重定向 URL 转到原始路径。
  • data - 要从中加载数据的文件。此数据以名为 self.data 的对象传递到 index.pug。您可以使用相对路径(./ 或 ../)。如果使用,它相对于 data.yaml 文件。根 (/) 路径是您的源文件夹(在 config.yaml 中设置)。

示例页面 data.yaml

path: /testpage1
aliases:
  - /test
  - /test123
data:
  news: ./datafiles/news.yaml
someOtherData:
  - A
  - B

页面样式 - style.styl

若要生成页面 CSS,请使用 **.styl** 文件。全局 style.css 由所有 .styl 文件(从源文件夹中)组合而成,并保存到生成文件夹的根文件夹中(如 /style.css)。

页面脚本 - script.js

若要生成页面 JS,请使用 **.js** 文件。全局 script.js 由所有 .js 文件(从源文件夹中)组合而成,并保存到生成文件夹的根文件夹中(如 /script.js)。

在生成过程中 ...

... 如该源文件夹 ...

- source
    |- _templates
    |   |- layout.pug
    |   |- mixins.pug
    |   +- somescripts.js
    |
    |- testpage1
    |   |- data.en.yaml
    |   |- data.et.yaml
    |   |- index.pug
    |   +- style.et.styl
    |
    |- testpage2
    |   |- index.en.pug
    |   |- index.et.pug
    |   |- data.yaml
    |   +- testpage2en
    |       |- index.en.pug
    |       +- data.en.yaml
    |
    |- index.pug
    +- style.styl

... 将转换到如下生成文件夹中

- build
    |- en
    |   |- index.html
    |   |- testpage1
    |   |   +- index.html
    |   |
    |   +- testpage2
    |       |- index.html
    |       +- testpage2en
    |           +- index.html
    |
    |- et
    |   |- index.html
    |   |- testpage1
    |   |   +- index.html
    |   |
    |   +- testpage2
    |       +- index.html
    |- script.js
    |- script.js.map
    |- style.css
    +- style.css.map

查找更多 静态站点生成器