Skip to content

Commit 886a14c

Browse files
committed
feat: add ability to link to git repo url #13
Closes #13
1 parent 62f41f6 commit 886a14c

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

src/createConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ function getPackageJSON() {
3535
svelte: pkg.svelte,
3636
description: pkg.description,
3737
homepage: pkg.homepage,
38+
repoUrl: pkg.repository?.url,
3839
};
3940
} catch (error) {
4041
console.log(error);

src/preprocessReadme.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ interface PreprocessReadmeOptions {
2222
svelte: string;
2323
prefixUrl: string;
2424
homepage: string;
25+
repoUrl: string;
2526
}
2627

2728
export function preprocessReadme(opts: Partial<PreprocessReadmeOptions>): Pick<PreprocessorGroup, "markup"> {
@@ -67,6 +68,10 @@ export function preprocessReadme(opts: Partial<PreprocessReadmeOptions>): Pick<P
6768
markup: ({ content, filename }) => {
6869
if (/node_modules/.test(filename) || !filename.endsWith(".md")) return null;
6970

71+
if (opts.repoUrl) {
72+
content = content.replace("<!-- REPO_URL -->", `[GitHub repo](${opts.repoUrl})`);
73+
}
74+
7075
content = content.replace(
7176
"<!-- TOC -->",
7277
`

test/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# my-svelte-component
22

3+
<!-- REPO_URL -->
4+
35
<!-- TOC -->
46

57
Relative URL: [Readme](./)

test/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@
1919
"serve": "^11.3.2",
2020
"svelte": "^3.29.7"
2121
},
22-
"homepage": "https://github.com/metonym/svelte-readme"
22+
"homepage": "https://github.com/metonym/svelte-readme",
23+
"repository": {
24+
"type": "git",
25+
"url": "https://github.com/metonym/svelte-readme"
26+
}
2327
}

0 commit comments

Comments
 (0)