Skip to content

Commit b12087e

Browse files
committed
feat(fetch): support gh: prefix
1 parent cbb521d commit b12087e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

docs/2.generators/fetch.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ The `fetch` generator fetches a URL (using [unjs/ofetch](https://ofetch.unjs.io)
4343
## Arguments
4444

4545
- `url`: The URL to fetch from
46+
47+
> [!TIP]
48+
> You can start url with `gh:` to use github contents!

src/generators/fetch.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@ export const fetch = defineGenerator({
44
name: "fetch",
55
async generate({ args }) {
66
const { $fetch } = await import("ofetch");
7-
const body = await $fetch(args.url);
7+
8+
let url = args.url;
9+
if (!url) {
10+
throw new Error("URL is required!");
11+
}
12+
if (url.startsWith("gh:")) {
13+
url = `https://raw.githubusercontent.com/${url.slice(3)}`;
14+
}
15+
16+
const contents = await $fetch(url);
17+
818
return {
9-
contents: body,
19+
contents,
1020
};
1121
},
1222
});

0 commit comments

Comments
 (0)