/** * All Rights Reserved * * Copyright (c) 2025 taskylizard * * All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder. */ import { fetcher } from 'itty-fetcher' // Look inside tbe docs directory const GITHUB_REPO = 'https://api.github.com/repos/wotakumoe/wotaku/contents/docs/' const EXCLUDE_FILES = ['README.md', 'index.md', 'credits.md', 'faq.md'] const EXCLUDE_DIRECTORIES = ['glossary/', 'guides/', 'torrenting/'] 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 = '\n' const f = fetcher({ headers: { 'User-Agent': 'taskylizard' } }) try { // Fetch the list of files in the repository const files = await f.get(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(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: appendResponseHeader(event, 'content-type', 'text/markdown;charset=utf-8') return body })