在前端开发的过程中,我们需要使用很多的工具来提高我们的生产效率。其中,Metalsmith 是一个类似于静态网站生成器的工具,它能够将一些文本、Markdown、HTML、CSS以及Javascript等资源,从一个文件夹转化为另一个文件夹中的静态网站。 metalsmith-asciidoc 这一 npm 包是为了支持 Asciidoc 的开发者所准备的。
安装 metalsmith-asciidoc
执行以下命令安装 metalsmith-asciidoc
:
npm install metalsmith-asciidoc --save
使用 metalsmith-asciidoc
步骤 1:配置源文件和目录
为了使用 metalsmith-asciidoc,我们需要明确以下 2 个输入参数:
- 源文件:输入文件的目录路径。
- 目标目录:生成文件的输出目录路径。
我们以实际的文件目录规划举例:
website │- docs │ └── asciidoc │ ├── index.js │ └── mypage.adoc ├── build.js └── dest
步骤 2:设置 metalsmith-asciidoc 插件
-- -------------------- ---- ------- --- ---------- - ---------------------- --- -------- - ------------------------------- --------------------- -------------------------- ----- ---------------------- ------ --------------- --------- - - -------- ------------ ------ -- ----- -- -------------- -- --------------- - -- ------ ----- --------- -- ----- ----------- ---------- -- ----- -------------- ------------ -- ---- ---------------- ------- - - - --- -------------------- - -- ----- -------- ---
步骤 3:运行你的代码
最后,运行你的代码,将会生成你的 asciidoc 文件:
node build.js
示例代码
= Hello World :author: Name :email: email@address.com Hello, [[world]]!
-- -------------------- ---- ------- --------- ----- ------ ------ ------------ ------------- ----- ------------- --------------- ----- ------------ ---------------------------- ------- ------ --------- -- ---------------------------- ------- -------
结论
通过本文的说明,我们能够了解到,metalsmith-asciidoc 用户可以用来将多种文本格式(包括 Asciidoc)转换成 HTML。同时我们还概述了 metalsmith 的基础,介绍了使用前端工具链增加内容复用和自动化程度的重要性。
来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/60066f431d8e776d08040e38