add wip loader
This commit is contained in:
parent
36a157b647
commit
b51440fb49
43
.vitepress/loaders/guides.data.ts
Normal file
43
.vitepress/loaders/guides.data.ts
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import { defineLoader } from "vitepress";
|
||||||
|
|
||||||
|
interface Data {
|
||||||
|
title?: string;
|
||||||
|
content?: string;
|
||||||
|
url?: string;
|
||||||
|
}
|
||||||
|
declare const data: Data;
|
||||||
|
export { data };
|
||||||
|
|
||||||
|
const page = "https://rentry.co/fmhy-guides/raw";
|
||||||
|
const regex = /\* \[([^\]]+)\]\(([^)]+)\)/g;
|
||||||
|
const rentryRe = /(?<=rentry\.(co|org)).*/;
|
||||||
|
const guides = new Set<Data>();
|
||||||
|
|
||||||
|
const f = async (url: string) => {
|
||||||
|
const contents = await (await fetch(url))
|
||||||
|
.text()
|
||||||
|
.catch((error: Error) => console.error(`Failed at ${url}`, error));
|
||||||
|
return contents;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default defineLoader({
|
||||||
|
async load(): Promise<Data> {
|
||||||
|
const contents = await f(page);
|
||||||
|
let match: any[] | null;
|
||||||
|
while ((match = regex.exec(contents)) !== null) {
|
||||||
|
const title = match[1];
|
||||||
|
const url = match[2];
|
||||||
|
// Fetch rentry guides
|
||||||
|
if (url.match(rentryRe)) {
|
||||||
|
const content = await f(url + "/raw");
|
||||||
|
guides.add({ title, content });
|
||||||
|
} else {
|
||||||
|
// Everything else can be here
|
||||||
|
guides.add({ title, url });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Object.fromEntries(
|
||||||
|
[...guides.entries()].map((entry, index) => [index.toString(), entry]),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
16
guides.md
Normal file
16
guides.md
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
title: Guides
|
||||||
|
---
|
||||||
|
<script setup>
|
||||||
|
import { data } from "./.vitepress/loaders/guides.data";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<h2>Guides</h2>
|
||||||
|
<br />
|
||||||
|
<ul>
|
||||||
|
<li v-for"link in data">
|
||||||
|
<a :href="link.url">{{ link.title }}</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</template>
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "fmhy",
|
"name": "fmhy",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"docs:dev": "vitepress dev",
|
"docs:dev": "vitepress dev",
|
||||||
"docs:build": "vitepress build",
|
"docs:build": "vitepress build",
|
||||||
|
Loading…
Reference in New Issue
Block a user