feat: reorganize repo

This commit is contained in:
taskylizard 2024-08-03 10:38:06 +00:00
parent 49eb39bc1f
commit 23389c69df
No known key found for this signature in database
GPG key ID: 1820131ED1A24120
107 changed files with 15 additions and 429 deletions

68
api/routes/single-page.ts Normal file
View file

@ -0,0 +1,68 @@
import { fetcher } from 'itty-fetcher'
const GITHUB_REPO = 'https://api.github.com/repos/fmhy/FMHYEdit/contents/'
const EXCLUDE_FILES = ['README.md', 'index.md', 'feedback.md', 'posts.md']
const EXCLUDE_DIRECTORIES = ['posts/']
interface File {
name: string
path: string
sha: string
size: number
url: string
html_url: string
git_url: string
download_url: string | null
type: string
_links: {
self: string
git: string
html: string
}
}
export default defineEventHandler(async (event) => {
let body = '<!-- This is autogenerated content, do not edit manually. -->\n'
const f = fetcher({
headers: {
'User-Agent': 'taskylizard'
}
})
try {
// Fetch the list of files in the repository
const files = await f.get<File[]>(GITHUB_REPO)
// Filter out the excluded files and non-markdown files
const markdownFiles = files.filter((file: File) => {
const isExcludedFile = EXCLUDE_FILES.includes(file.name)
const isInExcludedDirectory = EXCLUDE_DIRECTORIES.some((dir) =>
file.path.startsWith(dir)
)
const isMarkdownFile = file.name.endsWith('.md')
return isMarkdownFile && !isExcludedFile && !isInExcludedDirectory
})
// console.info(markdownFiles.map((f) => f.name))
// Fetch and concatenate the contents of the markdown files
const contents = await Promise.all(
markdownFiles.map(async (file: File) => {
const content = await f.get<string>(file.download_url)
return content
})
)
body += contents.join('\n\n')
} catch (error) {
return {
status: 500,
body: `Error fetching markdown files: ${error.message}`
}
}
// biome-ignore lint/correctness/noUndeclaredVariables: <explanation>
appendResponseHeader(event, 'content-type', 'text/markdown;charset=utf-8')
return body
})