Skip to content

Commit bf01198

Browse files
authored
Merge pull request #136 from docsbydoxdox/feature/pkg-homepage
[feat] Linked project title if homepage is defined in pkg.
2 parents 3c98fde + 89bbf1d commit bf01198

File tree

8 files changed

+39
-27
lines changed

8 files changed

+39
-27
lines changed

packages/doxdox-cli/src/index.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ describe('cli', () => {
3636
`./dist/src/index.js -n "testing the project name"`
3737
);
3838

39-
expect(stdout).toContain('# testing the project name');
39+
expect(stdout).toContain('# [testing the project name]');
4040
});
4141
it('set name (long flag)', async () => {
4242
const { stdout } = await execAsync(
4343
`./dist/src/index.js --name "testing the project name"`
4444
);
4545

46-
expect(stdout).toContain('# testing the project name');
46+
expect(stdout).toContain('# [testing the project name]');
4747
});
4848
it('set description (short flag)', async () => {
4949
const { stdout } = await execAsync(
@@ -74,17 +74,17 @@ describe('cli', () => {
7474
it('set output (no flag)', async () => {
7575
const { stdout } = await execAsync(`./dist/src/index.js`);
7676

77-
expect(stdout).toContain('# doxdox-cli');
77+
expect(stdout).toContain('# [doxdox-cli]');
7878
});
7979
it('set output (no directory)', async () => {
8080
const { stdout } = await execAsync(`./dist/src/index.js -o temp.md`);
8181

8282
await fs.stat('./temp.md');
8383

84-
expect(stdout).not.toContain('# doxdox-cli');
84+
expect(stdout).not.toContain('# [doxdox-cli]');
8585

8686
expect(await fs.readFile('./temp.md', 'utf8')).toContain(
87-
'# doxdox-cli'
87+
'# [doxdox-cli]'
8888
);
8989

9090
await fs.unlink('./temp.md');
@@ -96,10 +96,10 @@ describe('cli', () => {
9696

9797
await fs.stat('./src/temp.md');
9898

99-
expect(stdout).not.toContain('# doxdox-cli');
99+
expect(stdout).not.toContain('# [doxdox-cli]');
100100

101101
expect(await fs.readFile('./src/temp.md', 'utf8')).toContain(
102-
'# doxdox-cli'
102+
'# [doxdox-cli]'
103103
);
104104

105105
await fs.unlink('./src/temp.md');
@@ -111,10 +111,10 @@ describe('cli', () => {
111111

112112
await fs.stat('./temp/temp.md');
113113

114-
expect(stdout).not.toContain('# doxdox-cli');
114+
expect(stdout).not.toContain('# [doxdox-cli]');
115115

116116
expect(await fs.readFile('./temp/temp.md', 'utf8')).toContain(
117-
'# doxdox-cli'
117+
'# [doxdox-cli]'
118118
);
119119

120120
await fs.unlink('./temp/temp.md');
@@ -124,10 +124,10 @@ describe('cli', () => {
124124

125125
await fs.stat('./temp.md');
126126

127-
expect(stdout).not.toContain('# doxdox-cli');
127+
expect(stdout).not.toContain('# [doxdox-cli]');
128128

129129
expect(await fs.readFile('./temp.md', 'utf8')).toContain(
130-
'# doxdox-cli'
130+
'# [doxdox-cli]'
131131
);
132132

133133
await fs.unlink('./temp.md');
@@ -139,18 +139,18 @@ describe('cli', () => {
139139

140140
await fs.stat('./temp.md');
141141

142-
expect(stdout).not.toContain('# doxdox-cli');
142+
expect(stdout).not.toContain('# [doxdox-cli]');
143143

144144
expect(await fs.readFile('./temp.md', 'utf8')).toContain(
145-
'# doxdox-cli'
145+
'# [doxdox-cli]'
146146
);
147147

148148
await fs.unlink('./temp.md');
149149
});
150150
it('set package location (no flag)', async () => {
151151
const { stdout } = await execAsync(`./dist/src/index.js`);
152152

153-
expect(stdout).toContain('# doxdox-cli');
153+
expect(stdout).toContain('# [doxdox-cli]');
154154
});
155155
it('set package location (short flag)', async () => {
156156
const { stdout } = await execAsync(

packages/doxdox-cli/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ const overridePackage = String(
140140
const output = await doxdox(cwd, paths, loadedParser, loadedRenderer, {
141141
name: overrideName || pkg.name || 'Untitled Project',
142142
description: overrideDescription || pkg.description || '',
143-
version: pkg.version
143+
version: pkg.version,
144+
homepage: pkg.homepage
144145
});
145146

146147
if (overrideOutput) {

packages/doxdox-core/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ export * from './types.js';
22
export * from './utils.js';
33
export * from './loader.js';
44

5-
import { Doc, File } from './types.js';
5+
import { Doc, File, Options } from './types.js';
66

77
export default async (
88
cwd: string,
99
paths: string[],
1010
parser: (cwd: string, path: string) => Promise<File>,
1111
renderer: (doc: Doc) => Promise<string>,
12-
options: { name?: string; description?: string; version?: string } = {}
12+
options: Options = {}
1313
) =>
1414
Promise.all(paths.map(async path => await parser(cwd, path))).then(
1515
async files => await renderer({ ...options, files })

packages/doxdox-core/src/types.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
export interface Doc {
1+
export interface Options {
22
name?: string;
33
description?: string;
44
version?: string;
5+
homepage?: string;
6+
}
7+
8+
export interface Doc extends Options {
59
files: File[];
610
}
711

@@ -20,10 +24,7 @@ export interface Method {
2024
private: boolean;
2125
}
2226

23-
export interface Package {
24-
name?: string;
25-
description?: string;
26-
version?: string;
27+
export interface Package extends Options {
2728
exports?: string;
2829
}
2930

packages/doxdox-core/src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ export const getProjectPackage = async (cwd: string): Promise<Package> => {
8787
const projectPackagePath = await findFileInPath(cwd);
8888

8989
if (projectPackagePath) {
90-
const { name, description, version, exports } = JSON.parse(
90+
const { name, description, version, exports, homepage } = JSON.parse(
9191
await fs.readFile(projectPackagePath, 'utf8')
9292
);
9393

94-
return { name, description, version, exports };
94+
return { name, description, version, exports, homepage };
9595
}
9696

9797
return {};

packages/doxdox-renderer-bootstrap/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,11 @@ export default async (doc: Doc): Promise<string> => `<!DOCTYPE html>
130130
<body>
131131
<div class="bg-dark text-white">
132132
<div class="container p-5">
133-
<h1 class="pkg-name">${doc.name}</h1>
133+
${
134+
doc.homepage
135+
? `<h1 class="pkg-name"><a href="${doc.homepage}">${doc.name}</a></h1>`
136+
: `<h1 class="pkg-name">${doc.name}</h1>`
137+
}
134138
135139
${
136140
doc.description

packages/doxdox-renderer-markdown/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ ${param.description}`
3737
const renderFile = (file: File) =>
3838
`${file.methods.map(method => renderMethod(method)).join('')}`;
3939

40-
export default async (doc: Doc): Promise<string> => `# ${doc.name}
40+
export default async (doc: Doc): Promise<string> => `# ${
41+
doc.homepage ? `[${doc.name}](${doc.homepage})` : doc.name
42+
}
4143
4244
${doc.description ? `> ${doc.description}` : ''}
4345

packages/doxdox-renderer-pdf/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ export default async (doc: Doc): Promise<Buffer> => {
112112
<body>
113113
<div class="bg-dark text-white">
114114
<div class="container p-5">
115-
<h1 class="pkg-name">${doc.name}</h1>
115+
${
116+
doc.homepage
117+
? `<h1 class="pkg-name"><a href="${doc.homepage}">${doc.name}</a></h1>`
118+
: `<h1 class="pkg-name">${doc.name}</h1>`
119+
}
116120
117121
${
118122
doc.description

0 commit comments

Comments
 (0)