系列文档重构备注
撰写时间:2024-02-17
修订时间:2024-11-21
系列文档已可以做到根据一个JSON文件来自动生成左边导航区、右边导航区、下边导航区及索引页面的内容。
与之前的结构相比较,需作如下修改:
- 在各系列文档的根目录下新建serial-parts-struct.json文件,指定系列文章的标题及各个parts的标题、所含各篇文章的地址及标题。格式如下:
{ "title": "JavaScript Docs", "parts": { "基础篇": { "/docs/javascript/introduction/index.php": "概述", "/docs/javascript/datatypes/index.php": "基本数据类型", "/docs/javascript/string/index.php": "字符串", "/docs/javascript/array/index.php": "数组", "/docs/javascript/operators/index.php": "操作符", "/docs/javascript/function/index.php": "函数" }, "高级篇": { "/docs/javascript/Object/index.php": "Object", "/docs/javascript/promise/index.php": "Promise", "/docs/javascript/prototype/index.php": "Prototype", "/docs/javascript/regexp/index.php": "RegExp", "/docs/javascript/webworkers/index.php": "Web Workers", "/docs/javascript/xml/index.php": "XML操作" }, "综合篇": { "/docs/javascript/generation/iteration.php": "遍历", "/docs/javascript/generation/jsdoc.php": "JSDoc" }, "附录": { "/docs/javascript/appendices/ecma-tips.php": "ECMA规范使用技巧" } } } - 删除根目录下的serials-toc.php文件。该文件原由PHP来处理,现改由JavaScript根据上面的JSON文件来处理。
原因为:一是这些内容不属于服务器端的职责。二是可减轻服务器端的负担。三是JavaScript代码远比PHP灵活。
- 对于系列文档的每篇文章:
- 确保已包含:
<script type="module" src="/js/esm/gen-doc-toc.js"></script> 上面文件既向前兼容,同时也调用了gen-serial-nav.js模块文件。
- 删除以下语句:
<?php include 'serials-toc.php'; ?> - 删除以下这些语句:
gen-serial-nav.js负责自动生成上面两个方面的内容。以后,若有必要在页面顶端再添加一个导航栏,仅需修改该文件即可。
- 确保已包含:
- 对于系列文件根目录下的index.php文件:
- 确保已包含:
<script type="module" src="/js/esm/gen-serial-index.js"></script> 该文件为自调用模式,根据serial-parts-struct.json文件来自动生成索引页面的主体内容。
- 删除页面的title标签的内容。
- 删除main标签下的第一个section,其class属性为
first-sight
:... 上面两部分的内容已自动生成,可以安全删除。
- 确保已包含:
- 重构为支持多级子节点的.json文件。
重构的工作量很大,但重构后,后续撰写文章时工作量可大大减轻。并且,避免了不同步的问题。
这样重构后,网站内容的编写可用HTML 5的编写,但自动具备了DocBook 5的常用功能。