From b454f53352b45dada46c85f1f74fd90cb45d2786 Mon Sep 17 00:00:00 2001 From: teabyte Date: Sun, 7 Jan 2024 02:37:21 +0300 Subject: [PATCH] sitemap, robots --- components/EditButton.tsx | 1 + components/Nav.tsx | 8 ++++++-- courses/strings/intro.md | 2 -- main.ts | 31 ++++++++++++++++++++++++++++++- routes/[slug].tsx | 2 +- routes/_404.tsx | 4 +++- routes/index.tsx | 6 ++++-- static/robots.txt | 17 +++++++++++++++++ 8 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 static/robots.txt diff --git a/components/EditButton.tsx b/components/EditButton.tsx index a9d08d4..2960d38 100644 --- a/components/EditButton.tsx +++ b/components/EditButton.tsx @@ -4,6 +4,7 @@ export default function EditButton({ slug }: { slug: string }) { target="_blank" href={`https://github.com/TeaByte/NakhlahJS/edit/main/courses/${slug}.md`} class="pl-3 flex items-center gap-1 hover:opacity-75" + title="تعديل الملف" >
Website logo - + NakhlahJS
diff --git a/courses/strings/intro.md b/courses/strings/intro.md index 90cedf1..d4a5678 100644 --- a/courses/strings/intro.md +++ b/courses/strings/intro.md @@ -81,5 +81,3 @@ console.log(sampleStr); Hello World ``` - - diff --git a/main.ts b/main.ts index 675f529..e0966da 100644 --- a/main.ts +++ b/main.ts @@ -10,4 +10,33 @@ import { start } from "$fresh/server.ts"; import manifest from "./fresh.gen.ts"; import config from "./fresh.config.ts"; -await start(manifest, config); +import { freshSEOPlugin } from "https://deno.land/x/fresh_seo/mod.ts"; +import { walk } from "https://deno.land/std/fs/mod.ts"; + +async function getAllPaths(directory: string): Promise { + const paths: string[] = []; + for await (const entry of walk(directory, { includeDirs: false })) { + if (entry.isFile && entry.name.endsWith(".md")) { + const relativePath = entry.path.replace(/^courses[\\/]/, "").replace( + /\.md$/, + "", + ); + if (!relativePath.endsWith(".json")) { + paths.push(btoa(relativePath)); + } + } + } + return paths; +} + +const allPaths = await getAllPaths("courses"); +const coursesPath = allPaths.slice(1); +console.log(coursesPath); + +await start(manifest, { + plugins: [ + freshSEOPlugin(manifest, { + include: [...coursesPath], + }), + ], +}); diff --git a/routes/[slug].tsx b/routes/[slug].tsx index 016d998..c0fb04f 100644 --- a/routes/[slug].tsx +++ b/routes/[slug].tsx @@ -28,7 +28,7 @@ export default function CoursePage(props: PageProps) { Nakhlahjs - {course.title} - + diff --git a/routes/_404.tsx b/routes/_404.tsx index bc46b3c..b1a7dae 100644 --- a/routes/_404.tsx +++ b/routes/_404.tsx @@ -20,7 +20,9 @@ export default function Error404() {

الصفحة التي تبحث عنها غير موجودة.

- العودى الى الصفحة الرئيسية + + العودى الى الصفحة الرئيسية + diff --git a/routes/index.tsx b/routes/index.tsx index 3dd79f7..8268a07 100644 --- a/routes/index.tsx +++ b/routes/index.tsx @@ -69,12 +69,14 @@ export default function BlogIndexPage( return ( <> - الصفحه غير موجوده - +