Skip to content

Commit 6fa477a

Browse files
committed
feat(title): add title to every page
Now the frontmatter title is used as the main title Updated the example #14
1 parent 5d10de1 commit 6fa477a

File tree

15 files changed

+70
-19
lines changed

15 files changed

+70
-19
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![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)
44
[![npm](https://img.shields.io/npm/v/vuepress-jsdoc.svg)](https://www.npmjs.com/package/vuepress-jsdoc)
55

6-
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).
6+
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).
77

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

cmds/index.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,24 @@ async function generate(argv) {
123123
}
124124

125125
if (mdFileData) {
126-
const { frontmatter } = parseVuepressComment(fileData);
126+
const { frontmatter, attributes } = parseVuepressComment(fileData);
127127

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

130-
await fs.writeFile(
131-
`${folderPath}/${fileName}.md`,
132-
`---\n${frontmatter || `title: ${fileName}`}\n---\n${mdFileData}`
133-
);
130+
let fileContent = '---\n';
131+
132+
fileContent += !attributes || !attributes.title ? `title: ${file}` : '';
133+
134+
if (frontmatter) {
135+
fileContent += !attributes || !attributes.title ? '\n' : '';
136+
fileContent += `${frontmatter}`;
137+
}
138+
139+
fileContent += '\n---\n';
140+
fileContent += `\n# ${attributes && attributes.title ? attributes.title : file}\n\n`;
141+
fileContent += mdFileData;
142+
143+
await fs.writeFile(`${folderPath}/${fileName}.md`, fileContent);
134144

135145
tree.push({
136146
name: fileName,

example/documentation/code/class.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
---
2-
title: test class
2+
title: class.js
3+
test: test class
34
---
5+
6+
# class.js
7+
48
<a name="Test"></a>
59

610
## Test

example/documentation/code/config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ exports.fileTree = [
2020
]
2121
},
2222
{ name: 'test', path: '/test', fullPath: './documentation/code/test' },
23-
{ name: 'tests', children: [] }
23+
{ name: 'tests', children: [{ name: 'first.test', path: '/first.test', fullPath: 'tests/first.test' }] }
2424
];
2525
exports.sidebarTree = (title = 'Mainpage') => ({
2626
'/code/': [
2727
{ title: 'API', collapsable: false, children: [['', '' + title + ''], 'class', 'methods', 'objects', 'test'] },
2828
{ title: 'lib', collapsable: false, children: ['lib/dmd-options', 'lib/jsdoc-to-markdown'] },
29-
{ title: 'subfolder', collapsable: false, children: ['subfolder/subfolder.1/variables', 'subfolder/variables'] }
29+
{ title: 'subfolder', collapsable: false, children: ['subfolder/subfolder.1/variables', 'subfolder/variables'] },
30+
{ title: 'tests', collapsable: false, children: ['tests/first.test'] }
3031
]
3132
});

example/documentation/code/lib/dmd-options.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
2-
title: dmd-options
2+
title: dmd-options.js
33
---
4+
5+
# dmd-options.js
6+
47
<a name="DmdOptions"></a>
58

69
## DmdOptions

example/documentation/code/lib/jsdoc-to-markdown.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
2-
title: jsdoc-to-markdown
2+
title: jsdoc-to-markdown.js
33
---
4+
5+
# jsdoc-to-markdown.js
6+
47
<a name="module_jsdoc-to-markdown"></a>
58

69
## jsdoc-to-markdown

example/documentation/code/methods.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
22
title: A normal ES6 Method
33
---
4+
5+
# A normal ES6 Method
6+
47
## Functions
58

69
<dl>

example/documentation/code/objects.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
2-
title: objects
2+
title: objects.js
33
---
4+
5+
# objects.js
6+
47
<a name="obj"></a>
58

69
## obj

example/documentation/code/subfolder/subfolder.1/variables.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
2-
title: variables
2+
title: variables.js
33
---
4+
5+
# variables.js
6+
47
## Members
58

69
<dl>

example/documentation/code/subfolder/variables.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
2-
title: variables
2+
title: variables.js
33
---
4+
5+
# variables.js
6+
47
## Members
58

69
<dl>

example/documentation/code/test.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
2-
title: test
2+
title: test.vue
33
---
4+
5+
# test.vue
6+
47
# test
58

69
- **vue**
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: first.test.js
3+
---
4+
5+
# first.test.js
6+
7+
<a name="FirstTest"></a>
8+
9+
## FirstTest
10+
**Kind**: global class
11+
<a name="new_FirstTest_new"></a>
12+
13+
### new FirstTest()
14+
This is the FirstTest class
15+

example/src/class.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* @vuepress
33
* ---
4-
* title: test class
4+
* test: test class
55
* ---
66
*/
77
/**

helpers/comment-parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = fileContent => {
2020
);
2121
} catch (e) {
2222
return {
23-
fontmatter: null
23+
frontmatter: null
2424
};
2525
}
2626
};

tests/comment-parser.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ describe('commentParser', () => {
2626
});
2727

2828
describe('commentParser fail', () => {
29-
const { fontmatter } = commentParser();
29+
const { frontmatter } = commentParser();
3030

3131
test('fontmatter should be null', () => {
32-
expect(fontmatter).toBe(null);
32+
expect(frontmatter).toBe(null);
3333
});
3434
});

0 commit comments

Comments
 (0)