静态站点生成_探索Wyam-.NET静态站点内容生成器

静态站点生成

静态站点生成

It's a bit of a renaissance out there when it comes to Static Site Generators. There's Jekyll and GitBook, Hugo and Hexo. Middleman and Pelican, Brunch and Octopress. There's dozens, if not hundreds of static site content generators, and "long tail is long."

关于静态网站生成器,这有点复兴。 有Jekyll和GitBook,Hugo和Hexo。 Middleman和Pelican,Brunch和Octopress。 静态站点内容生成器有数十种(如果不是数百种),并且“长尾巴很长”。

Wyam is a great .NET based open source static site generator

Static Generators a nice for sites that DO get updated with dynamic content, but just not updated every few minutes. That means a Static Site Generator can be great for documentation, blogs, your brochure-ware home page, product catalogs, resumes, and lots more. Why install WordPress when you don't need to hit a database or generate HTML on every page view? Why not generate your site only when it changes?

静态生成器非常适合需要动态内容更新但并非每隔几分钟更新一次的站点。 这意味着静态站点生成器非常适合用于文档,博客,宣传册主页,产品目录,简历等。 当您不需要在每个页面视图上访问数据库或生成HTML时,为什么要安装WordPress 为什么不仅在网站更改时生成您的网站?

I recently heard about a .NET Core-based open source generator called Wyam and wanted to check it out.

我最近听说有一个名为Wyam的基于.NET Core的开源生成器,并想对其进行检查。

Wyam is a simple to use, highly modular, and extremely configurable static content generator that can be used to generate web sites, produce documentation, create ebooks, and much more.

Wyam是一个易于使用,高度模块化,可高度配置的静态内容生成器,可用于生成网站,生成文档,创建电子书等等。

Wyam is a module system with a pipeline that you can configure and chain processes together however you like. You can generate HTML from Markdown, from Razor, even XSLT2 - anything you like, really. Wyam also integrates nicely into your continuous build systems like Cake and others, so you can also get the Nuget Tools package for Wyam.

Wyam是带有管道的模块系统,您可以根据需要配置和链接流程。 您实际上可以从Markdown,Razor甚至XSLT2生成HTML。 Wyam还可以很好地集成到Cake和其他类似的连续构建系统中,因此您还可以获得Wyam的Nuget Tools软件包

There's a few ways to get Wyam but I downloaded the setup.exe from GitHub Releases. You can also just get a ZIP and download it to any folder. When I ran the setup.exe it flashed (I didn't see a dialog, but it's beta so I'll chalk it up to that) and it installed to C:\Users\scott\AppData\Local\Wyam with what looked like the Squirrel installer from GitHub and Paul Betts.

几种获取Wyam的方法,但我从GitHub Releases下载了setup.exe。 您也可以获取ZIP并将其下载到任何文件夹。 当我运行setup.exe时,它闪烁了(我没有看到对话框,但是它是beta版本,所以我将其归类为它),然后将其安装到C:\ Users \ scott \ AppData \ Local \ Wyam例如GitHub和Paul Betts的Squirrel安装程序

Wyam has a number of nice features that .NET Folks will find useful.

Wyam具有许多不错的功能,.NET Folks会发现它们有用。

Let's see what I can do with http://wyam.io in just a few minutes!

让我们看看几分钟后我可以使用http://wyam.io做什么!

搭建博客 (Scaffolding a Blog)

Wyam has a similar command line syntax as dotnet.exe and it uses "recipes" so I can say --recipe Blog and I'll get:

Wyam具有与dotnet.exe类似的命令行语法,并且使用“配方”,因此我可以说--recipe Blog,我将得到:

C:\Users\scott\Desktop\wyamtest>wyam new --recipe Blog
Wyam version 0.14.1-beta

,@@@@@ /@\ @@@@@
@@@@@@ @@@@@| $@@@@@h
$@@@@@ ,@@@@@@@ g@@@@@P
]@@@@@M g@@@@@@@ g@@@@@P
$@@@@@ @@@@@@@@@ g@@@@@P
j@@@@@ g@@@@@@@@@p ,@@@@@@@
$@@@@@g@@@@@@@@B@@@@@@@@@@@P
`$@@@@@@@@@@@` ]@@@@@@@@@`
$@@@@@@@P` ?$@@@@@P
`^`` *P*`
**NEW**
Scaffold directory C:/Users/scott/Desktop/wyamtest/input does not exist and will be created
Installing NuGet packages
NuGet packages installed in 101813 ms
Recursively loading assemblies
Assemblies loaded in 2349 ms
Cataloging classes
Classes cataloged in 277 ms

One could imagine recipes for product catalogs, little league sites, etc. You can make your own custom recipes as well.

您可以想象产品目录,小型联赛站点等的食谱。您也可以制作自己的自定义食谱。

I'll make a config.wyam file with this inside:

我将在其中创建一个config.wyam文件:

Settings.Host = "test.hanselman.com";
GlobalMetadata["Title"] = "Scott Hanselman";
GlobalMetadata["Description"] = "The personal wyam-made blog of Scott Hanselman";
GlobalMetadata["Intro"] = "Hi, welcome to my blog!";

Then I'll run wyam with:

然后,我将使用以下命令运行wyam:

C:\Users\scott\Desktop\wyamtest>wyam -r Blog
Wyam version 0.14.1-beta
**BUILD**
Loading configuration from file:///C:/Users/scott/Desktop/wyamtest/config.wyam
Installing NuGet packages
NuGet packages installed in 30059 ms
Recursively loading assemblies
Assemblies loaded in 368 ms
Cataloging classes
Classes cataloged in 406 ms
Evaluating configuration script
Evaluated configuration script in 2594 ms
Root path:
file:///C:/Users/scott/Desktop/wyamtest
Input path(s):
file:///C:/Users/scott/.nuget/packages/Wyam.Blog.CleanBlog.0.14.1-beta/content
theme
input
Output path:
output
Cleaning output path output
Cleaned output directory
Executing 7 pipelines
Executing pipeline "Pages" (1/7) with 8 child module(s)
Executed pipeline "Pages" (1/7) in 221 ms resulting in 13 output document(s)
Executing pipeline "RawPosts" (2/7) with 7 child module(s)
Executed pipeline "RawPosts" (2/7) in 18 ms resulting in 1 output document(s)
Executing pipeline "Tags" (3/7) with 10 child module(s)
Executed pipeline "Tags" (3/7) in 1578 ms resulting in 1 output document(s)
Executing pipeline "Posts" (4/7) with 6 child module(s)
Executed pipeline "Posts" (4/7) in 620 ms resulting in 1 output document(s)
Executing pipeline "Feed" (5/7) with 3 child module(s)
Executed pipeline "Feed" (5/7) in 134 ms resulting in 2 output document(s)
Executing pipeline "RenderPages" (6/7) with 3 child module(s)
Executed pipeline "RenderPages" (6/7) in 333 ms resulting in 4 output document(s)
Executing pipeline "Resources" (7/7) with 1 child module(s)
Executed pipeline "Resources" (7/7) in 19 ms resulting in 14 output document(s)
Executed 7/7 pipelines in 2936 ms

I can also run it with -t for different themes, like "wyam -r Blog -t Phantom":

我也可以使用-t来运行不同的主题,例如“ wyam -r Blog -t Phantom”:

As with most Static Site Generators I can start with a markdown file like "first-post.md" and included name value pairs of metadata at the top:

与大多数静态网站生成器一样,我可以从降价文件(例如“ first-post.md”)开始,并在顶部包含元数据的名称/值对:

Title: First Post
Published: 2016-01-01
Tags: Introduction
---
This is my first post!

If I'm working on my site a lot, I could run Wyam with the -w (WATCH) switch and then edit my posts in Visual Studio Code and Wyam will WATCH the input folder and automatically run over and over, regenerating the site each time I change the inputs! A nice little touch, indeed.

如果我经常在网站上工作,则可以使用-w(WATCH)开关运行Wyam,然后在Visual Studio Code中编辑我的帖子,Wyam将监视输入文件夹并自动运行,一遍又一遍地重新生成网站我更改输入的时间! 的确有点不错。

There's a lot of cool examples at https://github.com/Wyamio/Wyam/tree/develop/examples that show you how to generate RSS, do pagination, use Razor but still generate statically, as well as mixing Razor for layouts and Markdown for posts.

https://github.com/Wyamio/Wyam/tree/develop/examples上有很多很酷的示例,向您展示了如何生成RSS,进行分页,使用Razor但仍静态生成,以及混合Razor用于布局和降价张贴

The AdventureTime sample is fairly sophisticated (be sure to read the comments in the config.wyam for gotcha) example that includes a custom Pipeline, use of Yaml for front matter, and mixes markdown and Razor.

AdventureTime示例非常复杂(请务必阅读config.wyam中的注释以获取相关信息),该示例包括一个自定义管道,使用Yaml处理前端事务以及混合markdown和Razor。

There's also a ton of modules you can use to extend the build however you like. For example, you could have source images be large and then auto-generate thumbnails like this:

您还可以使用大量模块随意扩展构建。 例如,您可以将源图像放大,然后自动生成缩略图,如下所示:

Pipelines.Add("Images",
ReadFiles("*").Where(x => x.Contains("images\\") && new[] { ".jpg", ".jpeg", ".gif", ".png"}.Contains(Path.GetExtension(x))),
Image()
.SetJpegQuality(100).Resize(400,209).SetSuffix("-thumb"),
WriteFiles("*")
);

There's a TON of options. You could even use Excel as the source data for your site, generate CSVs from the Excel OOXML and then generate your site from those CSVs. Sounds crazy, but if you run a small business or non-profit you could quickly make a nice workflow for someone to take control of their own site!

有很多选择。 您甚至可以将Excel用作站点的源数据,从Excel OOXML生成CSV,然后从这些CSV生成站点。 听起来很疯狂,但是如果您经营一家小型企业或非营利组织,则可以快速建立一个不错的工作流程,让某人控制自己的网站!

GOTCHA: When generating a site locally your initial reaction may be to open the /output folder and open the index.html in your local browser. You MAY be disappointed with you use a static site generator. Often they generate absolute paths for CSS and Javascript so you'll see a lousy version of your website locally. Either change your templates to generate relative paths OR use a staging site and look at your sites live online. Even better, use the Wyam "preview web server" and run Wyam with a "-p" argument and then visit http://localhost:5080 to see your actual site as it will show up online.

GOTCHA:在本地生成站点时,您的最初React可能是打开/ output文件夹并在本地浏览器中打开index.html。 您可能对使用静态站点生成器感到失望。 通常,它们会生成CSS和Javascript的绝对路径,因此您会在本地看到糟糕的网站版本。 更改模板以生成相对路径,或者使用暂存站点并在线查看您的站点。 甚至更好的是,使用Wyam“预览Web服务器”并使用“ -p”参数运行Wyam,然后访问http:// localhost:5080以查看您的实际站点,因为该站点将在线显示。

Wyam looks like a really interesting start to a great open source project. It's got a lot of code, good docs, and it's easy to get started. It also has a bunch of advanced features that would enable me to easily embed static site generation in a dynamic app. From the comments, it seems that Dave Glick is doing most of the work himself. I'm sure he'd appreciate you reaching out and helping with some issues.

Wyam看起来是一个伟大的开源项目非常有趣的起点。 它有很多代码,优秀的文档,而且很容易上手。 它还具有许多高级功能,使我能够轻松地将静态网站生成嵌入动态应用程序中。 从评论中可以看出, Dave Glick亲自完成了大部分工作。 我相信他会感谢您提供帮助并解决一些问题的

As always, don't just send a PR without talking and working with the maintainers of your favorite open source projects. Also, ask if they have issues that are friendly to http://www.firsttimersonly.com.

与往常一样,不要不与您喜欢的开源项目的维护者讨论和合作就发送PR。 另外,询问他们是否有对http://www.firsttimersonly.com友好的问题。

翻译自: https://www.hanselman.com/blog/exploring-wyam-a-net-static-site-content-generator

静态站点生成

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值