Skip to content

Commit

Permalink
feat(title): add title to every page
Browse files Browse the repository at this point in the history
Now the frontmatter title is used as the main title
Updated the example

#14
  • Loading branch information
ph1p committed Feb 24, 2019
1 parent 5d10de1 commit 6fa477a
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/9ec565a85a134df2a0f6bdf905e438d4)](https://app.codacy.com/app/ph1p/vuepress-jsdoc?utm_source=github.com&utm_medium=referral&utm_content=ph1p/vuepress-jsdoc&utm_campaign=Badge_Grade_Settings)
[![npm](https://img.shields.io/npm/v/vuepress-jsdoc.svg)](https://www.npmjs.com/package/vuepress-jsdoc)

This npm package is a command line script, which scans your JavaScript, Vue or Typescript source code and generates markdown files for vuepress with the help of [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).
This npm package is a command line script, which scans your JavaScript, Vue or Typescript source code and generates markdown files for vuepress with the help of [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown) and [vuedoc](https://gitlab.com/vuedoc/md).

![CLI ./example](/example/img/cli.gif)

Expand Down
20 changes: 15 additions & 5 deletions cmds/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,24 @@ async function generate(argv) {
}

if (mdFileData) {
const { frontmatter } = parseVuepressComment(fileData);
const { frontmatter, attributes } = parseVuepressComment(fileData);

console.log(chalk.black.bgGreen('write file'), `${folderPath}/${fileName}.md`);

await fs.writeFile(
`${folderPath}/${fileName}.md`,
`---\n${frontmatter || `title: ${fileName}`}\n---\n${mdFileData}`
);
let fileContent = '---\n';

fileContent += !attributes || !attributes.title ? `title: ${file}` : '';

if (frontmatter) {
fileContent += !attributes || !attributes.title ? '\n' : '';
fileContent += `${frontmatter}`;
}

fileContent += '\n---\n';
fileContent += `\n# ${attributes && attributes.title ? attributes.title : file}\n\n`;
fileContent += mdFileData;

await fs.writeFile(`${folderPath}/${fileName}.md`, fileContent);

tree.push({
name: fileName,
Expand Down
6 changes: 5 additions & 1 deletion example/documentation/code/class.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
---
title: test class
title: class.js
test: test class
---

# class.js

<a name="Test"></a>

## Test
Expand Down
5 changes: 3 additions & 2 deletions example/documentation/code/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ exports.fileTree = [
]
},
{ name: 'test', path: '/test', fullPath: './documentation/code/test' },
{ name: 'tests', children: [] }
{ name: 'tests', children: [{ name: 'first.test', path: '/first.test', fullPath: 'tests/first.test' }] }
];
exports.sidebarTree = (title = 'Mainpage') => ({
'/code/': [
{ title: 'API', collapsable: false, children: [['', '' + title + ''], 'class', 'methods', 'objects', 'test'] },
{ title: 'lib', collapsable: false, children: ['lib/dmd-options', 'lib/jsdoc-to-markdown'] },
{ title: 'subfolder', collapsable: false, children: ['subfolder/subfolder.1/variables', 'subfolder/variables'] }
{ title: 'subfolder', collapsable: false, children: ['subfolder/subfolder.1/variables', 'subfolder/variables'] },
{ title: 'tests', collapsable: false, children: ['tests/first.test'] }
]
});
5 changes: 4 additions & 1 deletion example/documentation/code/lib/dmd-options.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
title: dmd-options
title: dmd-options.js
---

# dmd-options.js

<a name="DmdOptions"></a>

## DmdOptions
Expand Down
5 changes: 4 additions & 1 deletion example/documentation/code/lib/jsdoc-to-markdown.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
title: jsdoc-to-markdown
title: jsdoc-to-markdown.js
---

# jsdoc-to-markdown.js

<a name="module_jsdoc-to-markdown"></a>

## jsdoc-to-markdown
Expand Down
3 changes: 3 additions & 0 deletions example/documentation/code/methods.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
title: A normal ES6 Method
---

# A normal ES6 Method

## Functions

<dl>
Expand Down
5 changes: 4 additions & 1 deletion example/documentation/code/objects.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
title: objects
title: objects.js
---

# objects.js

<a name="obj"></a>

## obj
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
title: variables
title: variables.js
---

# variables.js

## Members

<dl>
Expand Down
5 changes: 4 additions & 1 deletion example/documentation/code/subfolder/variables.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
title: variables
title: variables.js
---

# variables.js

## Members

<dl>
Expand Down
5 changes: 4 additions & 1 deletion example/documentation/code/test.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
title: test
title: test.vue
---

# test.vue

# test

- **vue**
Expand Down
15 changes: 15 additions & 0 deletions example/documentation/code/tests/first.test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: first.test.js
---

# first.test.js

<a name="FirstTest"></a>

## FirstTest
**Kind**: global class
<a name="new_FirstTest_new"></a>

### new FirstTest()
This is the FirstTest class

2 changes: 1 addition & 1 deletion example/src/class.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @vuepress
* ---
* title: test class
* test: test class
* ---
*/
/**
Expand Down
2 changes: 1 addition & 1 deletion helpers/comment-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = fileContent => {
);
} catch (e) {
return {
fontmatter: null
frontmatter: null
};
}
};
4 changes: 2 additions & 2 deletions tests/comment-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ describe('commentParser', () => {
});

describe('commentParser fail', () => {
const { fontmatter } = commentParser();
const { frontmatter } = commentParser();

test('fontmatter should be null', () => {
expect(fontmatter).toBe(null);
expect(frontmatter).toBe(null);
});
});

0 comments on commit 6fa477a

Please sign in to comment.