javascript - JSDoc:如何在生成的文档中包含自定义 css 文件模板?

标签 javascript css jsdoc jsdoc3

JSDoc docs

Copying a directory of images to the output directory. To copy all of the static files in ./myproject/static to the output directory:

    "default": {
      "staticFiles": {
        "include": [
            "./myproject/static"
        ]
      }
    }

If your static files directory contains the file ./myproject/static/img/screen.png, you can display the image in your docs by using the HTML tag <img src="img/screen.png">.

所以我的 jsdoc.config.json 里有这个

    "templates": {
        "default": {
            "staticFiles": {
                "include": [
                    "doc/_static/css/index.css"
                ]
            }
        }
    }

我的 css 文件与我生成的文档一起添加到文件夹中,

但我真的希望我所有生成的文档都包含该 css 文件,而不必手动放置 <style src="index.css" />手动标记到我自动生成的文档中


它不在我自动生成的文档的头部,如下图所示

我希望头部是这样的

<head>
    <meta charset="utf-8">
    <title>JSDoc: Home</title>

    <script src="scripts/prettify/prettify.js"> </script>
    <script src="scripts/prettify/lang-css.js"> </script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="index.css">
</head>

最佳答案

我认为您可能需要使用 templates.default.layoutFile 配置属性提供自定义布局 (HTML) 文件。

"templates": {
    "default": {
        "layoutFile": "custom-layout.tmpl"
    }
}

文件的路径是相对于:

Relative paths are resolved against the current working directory; the path to the configuration file; and the JSDoc directory, in that order.


这是用于 templates.default.layoutfile 的示例模板文件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title><?js= title ?></title>
    <script src="scripts/prettify/prettify.js"></script>
    <script src="scripts/prettify/lang-css.js"></script>
    <link type="text/css" rel="stylesheet" href="dark.css">
    <link type="text/css" rel="stylesheet" href="index.css">
</head>
<body>

    <nav class="sidebar">
        <header class="nav-header">
            <a href="index.html">
                <img class="nav-logo" src="images/logo.svg" src="image" onerror="this.onerror=null; this.src='images/logo.png'" alt="alt text" />
                <h1>Project Name</h1>
            </a>
        </header>

        <?js= this.nav ?>
    </nav>

    <div id="main">
        <h1 class="page-title"><?js= title ?></h1>

        <?js= content ?>
    </div>

    <br class="clear">

    <footer>
        Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc <?js= env.version.number ?></a>
    </footer>

</body>
</html>

关于javascript - JSDoc:如何在生成的文档中包含自定义 css 文件模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71597572/

相关文章:

javascript - 观察使用 webpack 构建的 npm 链接包的变化

javascript - 确定函数是否在代理处理程序中被访问或调用

javascript - 如何在调整 td 元素大小时找到被 chop 的文本

javascript - 使用 Window.print 打印 HTML 页面

javascript - 我很难弄清楚如何动态设置时间线

javascript - 在 JSDoc 中记录开放式参数函数的正确方法

webstorm - 如何从 json 模式创建 jsdoc 类型

javascript - firefox 没有在使用框架的应用程序中选择最新的 css

html - Fontawesome webfont show square on content property(在本地工作正常并停留在产品环境中)

javascript - 为什么这个方法文档没有链接到指令文档?