Skip to content

Commit 155dfc0

Browse files
committed
feat: fetch generator
1 parent f24ace1 commit 155dfc0

File tree

7 files changed

+103
-1
lines changed

7 files changed

+103
-1
lines changed

docs/2.generators/fetch.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# fetch
2+
3+
The `fetch` generator fetches a URL (using [unjs/ofetch](https://ofetch.unjs.io)) and renders downloads content inside.
4+
5+
<!-- automd:example generator=fetch url="https://gist.github.com/pi0/c176defbba5568b6d06ea619a75f6104/raw" -->
6+
7+
## Example
8+
9+
### Input
10+
11+
<!-- automd:fetch url=https://gist.github.com/pi0/c176defbba5568b6d06ea619a75f6104/raw -->
12+
<!-- /automd -->
13+
14+
### Output
15+
16+
<!-- automd:fetch url=https://gist.github.com/pi0/c176defbba5568b6d06ea619a75f6104/raw -->
17+
18+
# The Lazy Coder's Guide to Programming
19+
20+
## Chapter 1: The Art of Copy-Pasting
21+
22+
### Section 1.1: Ctrl+C, Ctrl+V, Repeat
23+
24+
Programming can be hard. But fear not! With the power of copy-paste, you can conquer any coding challenge without breaking a sweat. Just remember: if it works once, it'll work a thousand times. Who needs original code anyway?
25+
26+
## Chapter 2: Debugging 101: Blame the Compiler
27+
28+
### Section 2.1: It's Not You, It's the Computer
29+
30+
When your code doesn't work, don't blame yourself. It's clearly the compiler's fault for not understanding your genius. Remember, the more error messages you get, the closer you are to becoming a programming master.
31+
32+
## Chapter 3: Stack Overflow: The Holy Grail
33+
34+
### Section 3.1: Why Figure It Out Yourself?
35+
36+
Why waste time solving problems when someone else has already done it for you? Stack Overflow is your best friend, your mentor, and your savior. Just make sure to upvote the answers that save your bacon.
37+
38+
39+
<!-- /automd -->
40+
41+
<!-- /automd -->
42+
43+
## Arguments
44+
45+
- `url`: The URL to fetch from

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"didyoumean2": "^6.0.1",
4444
"globby": "^14.0.1",
4545
"magic-string": "^0.30.7",
46+
"ofetch": "^1.3.3",
4647
"omark": "^0.1.0",
4748
"pathe": "^1.1.2",
4849
"pkg-types": "^1.0.3",

pnpm-lock.yaml

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/generators/fetch.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineGenerator } from "../generator";
2+
3+
export const fetch = defineGenerator({
4+
name: "fetch",
5+
async generate({ args }) {
6+
const { $fetch } = await import("ofetch");
7+
const body = await $fetch(args.url);
8+
return {
9+
contents: body,
10+
};
11+
},
12+
});

src/generators/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import { Generator } from "../generator";
22
import { jsdocs } from "./jsdocs";
33
import { badges } from "./badges";
44
import { pmX, pmInstall } from "./pm";
5+
import { fetch as _fetch } from "./fetch";
56

67
export default {
78
jsdocs,
89
badges,
910
"pm-i": pmInstall,
1011
"pm-install": pmInstall,
1112
"pm-x": pmX,
13+
fetch: _fetch,
1214
} as Record<string, Generator>;

test/fixture/INPUT.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@
1919

2020
<!-- automd:jsdocs -->
2121
<!-- /automd -->
22+
23+
## `fetch`
24+
25+
<!-- automd:fetch url="https://gist.github.com/pi0/c176defbba5568b6d06ea619a75f6104/raw" -->
26+
<!-- /automd -->

test/fixture/OUTPUT.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,31 @@ add(1, 2); // 3
7272
```
7373

7474

75+
<!-- /automd -->
76+
77+
## `fetch`
78+
79+
<!-- automd:fetch url="https://gist.github.com/pi0/c176defbba5568b6d06ea619a75f6104/raw" -->
80+
81+
# The Lazy Coder's Guide to Programming
82+
83+
## Chapter 1: The Art of Copy-Pasting
84+
85+
### Section 1.1: Ctrl+C, Ctrl+V, Repeat
86+
87+
Programming can be hard. But fear not! With the power of copy-paste, you can conquer any coding challenge without breaking a sweat. Just remember: if it works once, it'll work a thousand times. Who needs original code anyway?
88+
89+
## Chapter 2: Debugging 101: Blame the Compiler
90+
91+
### Section 2.1: It's Not You, It's the Computer
92+
93+
When your code doesn't work, don't blame yourself. It's clearly the compiler's fault for not understanding your genius. Remember, the more error messages you get, the closer you are to becoming a programming master.
94+
95+
## Chapter 3: Stack Overflow: The Holy Grail
96+
97+
### Section 3.1: Why Figure It Out Yourself?
98+
99+
Why waste time solving problems when someone else has already done it for you? Stack Overflow is your best friend, your mentor, and your savior. Just make sure to upvote the answers that save your bacon.
100+
101+
75102
<!-- /automd -->

0 commit comments

Comments
 (0)