From 6f3c6482386dc80741dff8bb397f671612f58382 Mon Sep 17 00:00:00 2001 From: Ankit Kumar Date: Tue, 7 Nov 2023 11:04:48 +0900 Subject: [PATCH] add target option in include scripts --- README.md | 30 +++++++++++++++++++++++++++++- clean-jsdoc-theme-helper.js | 23 ++++++++++++++--------- publish.js | 2 ++ 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a0fdb38a..1282804d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # clean-jsdoc-theme -[![Stars](https://img.shields.io/github/stars/ankitskvmdam/clean-jsdoc-theme)](https://github.com/ankitskvmdam/clean-jsdoc-theme) [![Fork](https://img.shields.io/github/forks/ankitskvmdam/clean-jsdoc-theme)](https://github.com/ankitskvmdam/clean-jsdoc-theme/fork) ![Version](https://img.shields.io/badge/version-4.2.14-005bff) [![Issues Open](https://img.shields.io/github/issues/ankitskvmdam/clean-jsdoc-theme)](https://github.com/ankitskvmdam/clean-jsdoc-theme/issues) [![Contributors](https://img.shields.io/github/contributors/ankitskvmdam/clean-jsdoc-theme)](https://github.com/ankitskvmdam/clean-jsdoc-theme/graphs/contributors) [![Build Status](https://travis-ci.org/ankitskvmdam/clean-jsdoc-theme.svg?branch=production)](https://travis-ci.org/ankitskvmdam/clean-jsdoc-theme) [![license](https://img.shields.io/github/license/ankitskvmdam/clean-jsdoc-theme)](https://github.com/ankitskvmdam/clean-jsdoc-theme/blob/master/LICENSE) +[![Stars](https://img.shields.io/github/stars/ankitskvmdam/clean-jsdoc-theme)](https://github.com/ankitskvmdam/clean-jsdoc-theme) [![Fork](https://img.shields.io/github/forks/ankitskvmdam/clean-jsdoc-theme)](https://github.com/ankitskvmdam/clean-jsdoc-theme/fork) ![Version](https://img.shields.io/badge/version-4.2.15-005bff) [![Issues Open](https://img.shields.io/github/issues/ankitskvmdam/clean-jsdoc-theme)](https://github.com/ankitskvmdam/clean-jsdoc-theme/issues) [![Contributors](https://img.shields.io/github/contributors/ankitskvmdam/clean-jsdoc-theme)](https://github.com/ankitskvmdam/clean-jsdoc-theme/graphs/contributors) [![Build Status](https://travis-ci.org/ankitskvmdam/clean-jsdoc-theme.svg?branch=production)](https://travis-ci.org/ankitskvmdam/clean-jsdoc-theme) [![license](https://img.shields.io/github/license/ankitskvmdam/clean-jsdoc-theme)](https://github.com/ankitskvmdam/clean-jsdoc-theme/blob/master/LICENSE)
`clean-jsdoc-theme` is a beautifully crafted theme for JSDoc 3/JSDoc 4. It is a clean and fully responsive theme with loads of @@ -480,6 +480,34 @@ Assuming the above js file is stored in `./static/showAlert.js`. To include you It will include the js files to the output dir and also attach a script tag to the html pointing to the included js file. +If you want to add some script for some pages then you can do the following: + +```json +"include_js": [ + "./demo/src/assets/script.js", + { + "filepath": "./demo/src/assets/random.js", + "targets": [ + "MyClass", + "tutorial-MyClassTutorial" + ] + } +], +``` + +Here target is the name of the generated html file (don't include `.html`). + +The above config will add `./demo/src/assets/script.js` to all the generated html files. However, it will +add `./demo/src/assets/random.js` only to `MyClass.html` and `tutorial-MyClassTutorial.html` files. + +The file name of the generated html generally follows the following convention: + +- Class: class's name + `.html`. Ex `Alive.html` +- Module: `module-` + module's name + `.html`. Ex: `module-SqlJs.html` +- Tutorials: `tutorial-` + tutorial's filename + `.html` + +If you are not sure about the target name, then generate html for the first time, then look at the urls. + ### To ignore sorting To ignore the sorting of members/methods/event in the page. If it is `false` then the order of diff --git a/clean-jsdoc-theme-helper.js b/clean-jsdoc-theme-helper.js index b7ef106a..5376a8cf 100644 --- a/clean-jsdoc-theme-helper.js +++ b/clean-jsdoc-theme-helper.js @@ -1,7 +1,7 @@ const has = require('lodash/has'); const klawSync = require('klaw-sync'); -const path = require('path') -const fse = require('fs-extra') +const path = require('path'); +const fse = require('fs-extra'); const showdown = require('showdown'); const mdToHTMLConverter = new showdown.Converter(); @@ -16,7 +16,7 @@ function lsSync(dir, opts = {}) { }); return files.map((f) => f.path); -}; +} function copyToOutputFolder(filePath, outdir) { const resolvedPath = path.resolve(filePath); @@ -31,8 +31,15 @@ function copyToOutputFolderFromArray(filePathArray, outdir) { if (Array.isArray(filePathArray)) { for (const filePath of filePathArray) { - copyToOutputFolder(filePath, outdir); - outputList.push(path.basename(filePath)); + if (typeof filePath === 'string') { + copyToOutputFolder(filePath, outdir); + outputList.push(path.basename(filePath)); + } else if (typeof filePath === 'object') { + const { filepath, targets } = filePath; + + copyToOutputFolder(filepath, outdir); + outputList.push({ filepath: path.basename(filepath), targets }); + } } } @@ -158,8 +165,6 @@ function getProcessedYield(yields) { })); } - - module.exports = { buildFooter, moduleHeader, @@ -177,5 +182,5 @@ module.exports = { returnPathOfStyleSrc, copyStaticFolder, getProcessedYield, - lsSync -} \ No newline at end of file + lsSync, +}; diff --git a/publish.js b/publish.js index 8bf55bf8..90e578d1 100644 --- a/publish.js +++ b/publish.js @@ -325,6 +325,7 @@ async function generate(title, docs, filename, resolveLinks) { env: env, title: title, docs: docs, + filename, }; outpath = path.join(outdir, filename); @@ -1016,6 +1017,7 @@ exports.publish = async function (taffyData, opts, tutorials) { header: tutorial.title, content: tutorial.parse(), children: tutorial.children, + filename, }; const tutorialPath = path.join(outdir, filename);