Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config and Plugin Support #14

Merged
merged 10 commits into from
Aug 19, 2020
Merged

Config and Plugin Support #14

merged 10 commits into from
Aug 19, 2020

Conversation

aemmadi
Copy link
Owner

@aemmadi aemmadi commented Aug 18, 2020

This PR includes:

Config

  • Now scans /:user/:repo for a .fastdocs.json config file. This allows fastdocs to know which plugins to add when rendering the docs.
  • Defaults to rendering without config if any error is thrown during parsing the config.

Current Config:

{
  "description": "Description",
  "plugins": [],
  "gaCode": ""    
}

gaCode is only required when google-analytics is added to the plugins array

Plugins

  • Added support for most major plugins on docsify that were determined to be "lightweight" enough to be added to the fastdocs microservice. These include:
    • docsify-copy-code: Adds a "Copy to Clipboard" next to code blocks
    • full-text-search: Adds a search bar on the top of the sidebar to quickly search docs
    • google-analytics: Support for google analytics
      • Need to provide the google analytics code inside gaCode on the config.
    • emoji: Renders emoji's in your documentation. (Ex: :100: would render to 💯)
    • zoom-image: Adds subtle zooming to images cursor is hovering

@aemmadi aemmadi requested a review from ianjennings August 18, 2020 21:34
@aemmadi aemmadi added the enhancement New feature or request label Aug 18, 2020
This was linked to issues Aug 18, 2020
app.js Outdated
Comment on lines 14 to 23
try {
util.compileDocs(user, repo).then(() => {
util.serveDocs(app, user, repo);
res.send(`Successfully Compiled Docs! View them at /${user}/${repo}`);
});
} catch (error) {
res.send(
`Oops. We couldn't render these docs. Check your config if you have one and try again!`
);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does compileDocs have an error handler? That would be better than try / catch

Comment on lines +1 to +5
{
"description": "Description",
"plugins": [],
"gaCode": ""
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request description says this isn'' required right? Is this an example?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the config.json here is just the list of supported keys that can be used

docsify.js Outdated Show resolved Hide resolved
plugins.js Show resolved Hide resolved
Comment on lines +57 to +89
try {
Object.keys(config).forEach((key) => {
mainConfig[`${key}`] = config[key];
});

mainConfig.enablePlugins = false;
if (mainConfig.plugins.length > 0) {
mainConfig.enablePlugins = true;
}

if (mainConfig.enablePlugins) {
const pluginConfig = plugins.addPlugins(mainConfig.plugins);
mainConfig.plugins = pluginConfig;
}

const htmlData = docsify.generateHtmlWithConfig(mainConfig);

fs.writeFileSync(`./docs/${user}-${repo}/README.md`, readmeData, function (
err
) {
if (err) throw err;
console.log("Generated ReadMe!");
});

fs.writeFileSync(`./docs/${user}-${repo}/index.html`, htmlData, function (
err
) {
if (err) throw err;
console.log("Generated HTML!");
});
} catch (error) {
writeDocsWithDefaultConfig(user, repo, readmeData);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, interesting read. Will look more into error handling with callback functions. Future refactor!!

util.js Outdated Show resolved Hide resolved
@aemmadi aemmadi merged commit 77920ab into master Aug 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a docsifyup.json Add more plugins Prototype Plugin Script
2 participants