Skip to content

Commit

Permalink
feat: fetch generator
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 15, 2024
1 parent f24ace1 commit 155dfc0
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 1 deletion.
45 changes: 45 additions & 0 deletions docs/2.generators/fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# fetch

The `fetch` generator fetches a URL (using [unjs/ofetch](https://ofetch.unjs.io)) and renders downloads content inside.

<!-- automd:example generator=fetch url="https://gist.github.com/pi0/c176defbba5568b6d06ea619a75f6104/raw" -->

## Example

### Input

<!-- automd:fetch url=https://gist.github.com/pi0/c176defbba5568b6d06ea619a75f6104/raw -->
<!-- /automd -->

### Output

<!-- automd:fetch url=https://gist.github.com/pi0/c176defbba5568b6d06ea619a75f6104/raw -->

# The Lazy Coder's Guide to Programming

## Chapter 1: The Art of Copy-Pasting

### Section 1.1: Ctrl+C, Ctrl+V, Repeat

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?

## Chapter 2: Debugging 101: Blame the Compiler

### Section 2.1: It's Not You, It's the Computer

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.

## Chapter 3: Stack Overflow: The Holy Grail

### Section 3.1: Why Figure It Out Yourself?

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.


<!-- /automd -->

<!-- /automd -->

## Arguments

- `url`: The URL to fetch from
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"didyoumean2": "^6.0.1",
"globby": "^14.0.1",
"magic-string": "^0.30.7",
"ofetch": "^1.3.3",
"omark": "^0.1.0",
"pathe": "^1.1.2",
"pkg-types": "^1.0.3",
Expand Down
12 changes: 11 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/generators/fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineGenerator } from "../generator";

export const fetch = defineGenerator({
name: "fetch",
async generate({ args }) {
const { $fetch } = await import("ofetch");
const body = await $fetch(args.url);
return {
contents: body,
};
},
});
2 changes: 2 additions & 0 deletions src/generators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { Generator } from "../generator";
import { jsdocs } from "./jsdocs";
import { badges } from "./badges";
import { pmX, pmInstall } from "./pm";
import { fetch as _fetch } from "./fetch";

export default {
jsdocs,
badges,
"pm-i": pmInstall,
"pm-install": pmInstall,
"pm-x": pmX,
fetch: _fetch,
} as Record<string, Generator>;
5 changes: 5 additions & 0 deletions test/fixture/INPUT.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@

<!-- automd:jsdocs -->
<!-- /automd -->

## `fetch`

<!-- automd:fetch url="https://gist.github.com/pi0/c176defbba5568b6d06ea619a75f6104/raw" -->
<!-- /automd -->
27 changes: 27 additions & 0 deletions test/fixture/OUTPUT.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,31 @@ add(1, 2); // 3
```


<!-- /automd -->

## `fetch`

<!-- automd:fetch url="https://gist.github.com/pi0/c176defbba5568b6d06ea619a75f6104/raw" -->

# The Lazy Coder's Guide to Programming

## Chapter 1: The Art of Copy-Pasting

### Section 1.1: Ctrl+C, Ctrl+V, Repeat

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?

## Chapter 2: Debugging 101: Blame the Compiler

### Section 2.1: It's Not You, It's the Computer

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.

## Chapter 3: Stack Overflow: The Holy Grail

### Section 3.1: Why Figure It Out Yourself?

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.


<!-- /automd -->

0 comments on commit 155dfc0

Please sign in to comment.