import jsonData from "../static/docs.json" with { type: "json" }; import type { Handlers, PageProps } from "$fresh/server.ts"; import { renderMarkdown } from "../utils/render_markdown.ts"; import { Header } from "../components/Header.tsx"; import { Rule, RuleData } from "../components/Rule.tsx"; export const handler: Handlers = { GET(_req, ctx) { const rules = jsonData.map((rule) => ({ code: rule.code, snippet: renderMarkdown(rule.docs.split("\n")[0]), docs: renderMarkdown(rule.docs.split("\n").slice(1).join("\n")), tags: rule.tags, })); return ctx.render(rules); }, }; export default function Home(props: PageProps) { const rules = props.data; const search = props.url.searchParams.get("q") ?? ""; const allRules = props.url.searchParams.has("all"); const searchResults = rules .filter((rule: RuleData) => { if (allRules) { return true; } else { return rule.tags.includes("recommended") || rule.tags.includes("fresh"); } }) .filter((rule: RuleData) => rule.code.includes(search)); return (
Showing {searchResults.length} out of {rules.length} rules
{searchResults .map((rule: RuleData) => )}
); }