Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzhitong committed May 28, 2021
1 parent 6aa939f commit 524f34d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 84 deletions.
6 changes: 0 additions & 6 deletions NeoDocsBuilder/ConfigItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,13 @@ public class ConfigItem
{
public string Origin;
public string Destination;
public string Template;
public string Catalog;
public string Git;
public string WebRoot;
public JObject FolderJson;
public ConfigItem(JToken json)
{
Origin = json["origin"].ToString();
Destination = json["destination"].ToString();
Template = json["template"].ToString();
Catalog = json["catalog"].ToString();
Git = json["git"].ToString();
WebRoot = json["webRoot"].ToString();
var jsonPath = Path.Combine(Origin, "folder.json");
if (!File.Exists(jsonPath))
{
Expand Down
40 changes: 15 additions & 25 deletions NeoDocsBuilder/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,28 @@ class Program
static void Main(string[] args)
{
var t1 = DateTime.Now;
Config.ConfigFile = args.Length > 1 ? args[0] : "config.json"; //设置配置文件
Config.ConfigFile = "config.json"; //设置配置文件

foreach (var item in Config.ConfigList)
{
Console.WriteLine("Beginning……");
AllMdFiles.Clear();
GetAllMdFiles(item.Origin);


//复制模板到网站根目录,包括 CSS、JS、字体、图片等,不包含 .md .json .yml
Console.WriteLine("Copy template files……");
Files.CopyDirectory(item.Template, item.WebRoot); //复制模板到网站根目录,包括 CSS、JS、字体、图片等,不包含 .md .json .yml
Files.CopyDirectory("template", "wwwroot");

//复制源文件夹中的资源文件到输出目录,包括图片等,不包含 .md .json .yml
Console.WriteLine("Copy source files……");
Files.CopyDirectory(item.Origin, item.Destination); //复制源文件夹中的资源文件到输出目录,包括图片等,不包含 .md .json .yml
Files.CopyDirectory(item.Origin, item.Destination);

Console.WriteLine("Build catalog……");
var catalog = YmlConverter.ToHtml(item.Catalog, Path.GetFullPath(Config.ConfigFile).Replace(Config.ConfigFile, ""));
foreach (var md in AllMdFiles)
var catalog = YmlConverter.ToHtml(Path.Combine(item.Origin, "toc.yml"), Path.GetFullPath(Config.ConfigFile).Replace(Config.ConfigFile, ""));
AllMdFiles.ForEach(md =>
{
if (!catalog.Contains(md.Replace("\\", "/").Replace(".md", ".html")) && !md.Contains("framework"))
{
if (!catalog.Contains(md.Replace("\\", "/").Replace(".md", ".html")))
YmlConverter.ErrorLogs.Add($"The file is not in the catalog: {md}");
}
}
});
BuildMarkDown(catalog, item); //对 MarkDown 文件夹进行解析、编译以及样式处理
}
var t2 = DateTime.Now;
Expand All @@ -59,14 +57,8 @@ static void Main(string[] args)
}
Console.ForegroundColor = ConsoleColor.White;

try
{
File.WriteAllText("log.txt", $"{DateTime.Now}");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
try { File.WriteAllText("log.txt", $"{DateTime.Now}"); } catch (Exception) { }

Console.WriteLine("Press 'Enter' key in 3 seconds to pause...");
Thread t = new(new ThreadStart(ConsolePause));
t.Start();
Expand Down Expand Up @@ -114,7 +106,7 @@ static void BuildMarkDown(string catalog, ConfigItem config)
//生成后的文件路径
var newFile = Path.Combine(config.Destination, relativeToOrigin.Replace(".md", ".html")).ToLower();
var git = Path.Combine(config.Git, relativeToOrigin);
Build(newFile, catalog, content, title, sideNav, git, config.Template, collapse);
Build(newFile, catalog, content, title, sideNav, git, collapse);
});
}

Expand Down Expand Up @@ -214,15 +206,13 @@ static void BuildMarkDown(string catalog, ConfigItem config)
/// <param name="content">正文(HTML)</param>
/// <param name="title">标题(TXT)</param>
/// <param name="sideNav">文章内的目录(HTML)</param>
/// <param name="depth">该文件相对于根目录(Origin)的层级深度</param>
/// <param name="template">HTML 模板的文件名</param>
/// <param name="collapse">是否对内容进行折叠</param>
static void Build(string path, string catalog, string content, string title, string sideNav, string git, string template, bool collapse)
static void Build(string path, string catalog, string content, string title, string sideNav, string git, bool collapse)
{
try
{
using StreamWriter sw = new(path);
sw.WriteLine(File.ReadAllText(Path.Combine(template, "template.html"))
sw.WriteLine(File.ReadAllText("template/template.html")
.Replace("{title}", title)
.Replace("{git}", git)
.Replace("{sideNav}", sideNav)
Expand All @@ -231,7 +221,7 @@ static void Build(string path, string catalog, string content, string title, str
.Replace("_collapse", collapse.ToString().ToLower()));
Console.WriteLine($"build: {path}");
}
catch (System.Exception e)
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Expand Down
84 changes: 31 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,33 @@

NeoDocsBuilder —— 一个超牛逼的 MarkDown 转网站的工具,包括解析、编译、样式处理以及高度定制化功能

| 周期 | 功能 | 状态 | 说明 | 开源库 |
| ---- | -------------------------------- | ------ | ------------------------------------------------------------ | -------------------------------------- |
| 1 | MarkDown 解析 | 已完成 | 对 MarkDown 文档进行解析 | Microsoft.Toolkit.Parsers.Markdown |
| 1 | MarkDown - HTML 的转换 | 已完成 | 将已解析的 MarkDown 转换为 HTML | |
| 1 | 多文档自动转换 | 已完成 | 针对一个文件夹内的多级目录以 及多个 .md 文件自动生成 HTML | |
| 1 | Bootstrap4 集成 | 已完成 | 生成带 Bootstrap4 样式的 HTML | Bootstrap |
| 1 | 自动目录生成 `已弃用` | 已完成 | 根据目录结构生成文档目录。参见:[auto-generate-catalog-orderd-by-name](https://github.com/chenzhitong/NeoDocsBuilder/tree/auto-generate-catalog-orderd-by-name) 分支 | |
| 1 | 目录中文件夹的自定义配置`已弃用` | 已完成 | 配置 folder.json 实现文件夹的重命名和隐藏 | |
| 1 | 手动目录生成 `` | 已完成 | 根据 toc.yml 生成目录 | |
| 1 | 网站模板 | 已完成 | 开发 docs.neo.org 的前端页面的模板 | |
| 1 | 自适应 HTML 编码 | 已完成 | 根据 MarkDown 中的标签内容,进行正确的 HtmlEncode, 以使某些标签按文本显示,某些标签按代码显示 | |
| 1 | 动态目录生成 `已弃用` | 已完成 | 为每篇文档生成不同的相对路径的目录, 以兼容 [file://](file:///) 协议 | |
| | Less 支持 `` | 已完成 | 用 Less 重写 CSS 以快速更改主题色,与 files:// 协议不兼容 | |
| 1 | 文章摘要和锚点的自动生成 | 已完成 | 为每篇文档自动生成右侧的章节列表, 点击可进行文档内的跳转 | |
| 1 | 滚动监听 | 已完成 | 右侧章节列表的滚动监听,文章滚动到某个章节,右侧章节列表高亮显示 | bootstrap - scrollspy |
| 1 | 当前位置定位,及目录高亮 | 已完成 | 对当前阅读的文档和标题进行定位,在左侧目录和右侧摘要处高亮显示 | |
| 1 | 懒加载 | 已完成 | 对图片进行懒加载 | jquey.lazyload |
| 1 | 代码高亮 | 已完成 | 对代码进行高亮显示 | highlight.js Visual Studio-like style |
| 1 | 针对标题进行折叠展开 | 已完成 | 适用于 FAQ 之类的大量需要折叠的内容 | |
| 1 | 多语言切换 | 已完成 | 网站多语言切换以及内容的多语言切换 | |
| 1 | GitHub 链接 | 已完成 | 对每篇文档添加对应的 GitHub 链接 | |
| 2 | 死链检测 | 已完成 | 对所引用的 .md 做死链检测 | |
| 2 | 全局搜索 | 已完成 | 对文档内容进行全文搜索(独立部署) | |
| 2 | 代码片段复制 | 已完成 | 一键复制文档中的代码片断 | clipboard.js |
| 2 | 版本切换 | 已完成 | 在网站中可以设置版本,并且支持切换 | |
| 2 | 多主题切换 | 已完成 | 支持自定义主题,如深色模式 | |
| 2 | Tab 页支持 | 未完成 | 为 MarkDown 支持页面内的 Tabs | |
| 2 | 反馈建议 | 已完成 | 用户可以提交对文档的反馈 | |
| 功能 | 状态 | 说明 | 开源库 |
| -------------------------------- | ------ | ------------------------------------------------------------ | -------------------------------------- |
| MarkDown 解析 | 已完成 | 对 MarkDown 文档进行解析 | Microsoft.Toolkit.Parsers.Markdown |
| MarkDown - HTML 的转换 | 已完成 | 将已解析的 MarkDown 转换为 HTML | |
| 多文档自动转换 | 已完成 | 针对一个文件夹内的多级目录以 及多个 .md 文件自动生成 HTML | |
| Bootstrap4 集成 | 已完成 | 生成带 Bootstrap4 样式的 HTML | Bootstrap |
| 自动目录生成 `已弃用` | 已完成 | 根据目录结构生成文档目录。参见:[auto-generate-catalog-orderd-by-name](https://github.com/chenzhitong/NeoDocsBuilder/tree/auto-generate-catalog-orderd-by-name) 分支 | |
| 目录中文件夹的自定义配置`已弃用` | 已完成 | 配置 folder.json 实现文件夹的重命名和隐藏 | |
| 手动目录生成 `` | 已完成 | 根据 toc.yml 生成目录 | |
| 网站模板 | 已完成 | 开发 docs.neo.org 的前端页面的模板 | |
| 自适应 HTML 编码 | 已完成 | 根据 MarkDown 中的标签内容,进行正确的 HtmlEncode, 以使某些标签按文本显示,某些标签按代码显示 | |
| 动态目录生成 `已弃用` | 已完成 | 为每篇文档生成不同的相对路径的目录, 以兼容 [file://](file:///) 协议 | |
| Less 支持 `` | 已完成 | 用 Less 重写 CSS 以快速更改主题色,与 files:// 协议不兼容 | |
| 文章摘要和锚点的自动生成 | 已完成 | 为每篇文档自动生成右侧的章节列表, 点击可进行文档内的跳转 | |
| 滚动监听 | 已完成 | 右侧章节列表的滚动监听,文章滚动到某个章节,右侧章节列表高亮显示 | bootstrap - scrollspy |
| 当前位置定位,及目录高亮 | 已完成 | 对当前阅读的文档和标题进行定位,在左侧目录和右侧摘要处高亮显示 | |
| 懒加载 | 已完成 | 对图片进行懒加载 | jquey.lazyload |
| 代码高亮 | 已完成 | 对代码进行高亮显示 | highlight.js Visual Studio-like style |
| 针对标题进行折叠展开 | 已完成 | 适用于 FAQ 之类的大量需要折叠的内容 | |
| 多语言切换 | 已完成 | 网站多语言切换以及内容的多语言切换 | |
| GitHub 链接 | 已完成 | 对每篇文档添加对应的 GitHub 链接 | |
| 死链检测 | 已完成 | 对所引用的 .md 做死链检测 | |
| 全局搜索 | 已完成 | 对文档内容进行全文搜索(独立部署) | |
| 代码片段复制 | 已完成 | 一键复制文档中的代码片断 | clipboard.js |
| 版本切换 | 已完成 | 在网站中可以设置版本,并且支持切换 | |
| 多主题切换 | 已完成 | 支持自定义主题,如深色模式 | |
| 反馈建议 | 已完成 | 用户可以提交对文档的反馈 | |

## 运行

Expand All @@ -41,33 +40,24 @@ NeoDocsBuilder —— 一个超牛逼的 MarkDown 转网站的工具,包括解
dotnet NeoDocsBuilder.dll
```

文档目录参考:https://github.com/neo-project/docs

```powershell
dotnet NeoDocsBuilder.dll config.json
```
注意配置 config.json 文件和 toc.yml 文件。

## 配置文件说明

**config.json**

origin:存储 MarkDown 文件的文件夹,作为编译的输入

template:存储网站模板的文件夹,作为编译时候的模板

destination:存储编译结果的文件夹,作为编译的输出

webRoot:网站根据目录,程序会将 template 中的内容(如 CSS,JS)复制到网站根目录

```json
{
"ApplicationConfiguration": [
{
"origin": "origin\\zh-cn",
"template": "template",
"destination": "wwwroot\\zh-cn",
"catalog": "docs\\zh-cn\\toc.yml",
"webRoot": "wwwroot",
"git": "https://github.com/neo-project/docs/blob/master/zh-cn/"
}
]
Expand All @@ -81,34 +71,22 @@ webRoot:网站根据目录,程序会将 template 中的内容(如 CSS,JS
"ApplicationConfiguration": [
{
"origin": "docs\\zh-cn",
"template": "template",
"destination": "wwwroot\\docs\\zh-cn",
"catalog": "docs\\zh-cn\\toc.yml",
"webRoot": "wwwroot",
"git": "https://github.com/neo-project/docs/blob/master/docs/zh-cn/"
},
{
"origin": "docs\\en-us",
"template": "template",
"destination": "wwwroot\\docs\\en-us",
"catalog": "docs\\en-us\\toc.yml",
"webRoot": "wwwroot",
"git": "https://github.com/neo-project/docs/blob/master/docs/en-us/"
},
{
"origin": "faq\\zh-cn",
"template": "template",
"destination": "wwwroot\\faq\\zh-cn",
"catalog": "faq\\zh-cn\\toc.yml",
"webRoot": "wwwroot",
"git": "https://github.com/neo-project/docs/blob/master/faq/zh-cn/"
},
{
"origin": "faq\\en-us",
"template": "template",
"destination": "wwwroot\\faq\\en-us",
"catalog": "faq\\en-us\\toc.yml",
"webRoot": "wwwroot",
"git": "https://github.com/neo-project/docs/blob/master/faq/en-us/"
}
]
Expand Down Expand Up @@ -163,7 +141,7 @@ collapse:生成文档内容时,对二级标题下的所有内容进行折叠

## 配置 SearchEngine

SearchEngine 是一个 ASP.NET Core 3.0 的网站,为文档提供后端的搜索功能,部署方式如下:
SearchEngine 是一个 ASP.NET Core 5.0 的网站,为文档提供后端的搜索功能,部署方式如下:

1、发布 SearchEngine 项目,生成如下文件

Expand Down Expand Up @@ -227,4 +205,4 @@ web.config

5、运行 SearchEngine 网站,可以在 IIS 中运行,也可以在本地直接运行 SearchEngine.exe。

需要安装 [.NET Core 3.0 Runtime & Hosting Bundle](https://dotnet.microsoft.com/download/dotnet-core/3.0/runtime)
需要安装 [.NET 5.0 Runtime](https://dotnet.microsoft.com/download/dotnet/5.0/runtime)

0 comments on commit 524f34d

Please sign in to comment.