-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update editor.defaultFormatter and start script
- Loading branch information
1 parent
4d56181
commit 7dd4827
Showing
10 changed files
with
93 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
"check": "deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx", | ||
"cli": "echo \"import '\\$fresh/src/dev/cli.ts'\" | deno run --unstable -A -", | ||
"manifest": "deno task cli manifest $(pwd)", | ||
"start": "deno run -A --watch=static/,routes/ --unstable dev.ts", | ||
"start": "deno run -A --watch=static/,routes/,plugins/ --unstable dev.ts", | ||
"build": "deno run --unstable -A dev.ts build", | ||
"preview": "deno run --unstable -A main.ts", | ||
"update": "deno run -A -r https://fresh.deno.dev/update ." | ||
|
@@ -23,8 +23,7 @@ | |
"tailwindcss/plugin": "npm:/[email protected]/plugin.js", | ||
"$std/": "https://deno.land/[email protected]/", | ||
"$gfm": "https://deno.land/x/[email protected]/mod.ts", | ||
"daisyui": "npm:daisyui@latest", | ||
"zod": "https://esm.sh/[email protected]" | ||
"daisyui": "npm:daisyui@latest" | ||
}, | ||
"compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "preact" }, | ||
"nodeModulesDir": true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import { defineConfig } from "$fresh/server.ts"; | ||
import tailwind from "$fresh/plugins/tailwind.ts"; | ||
|
||
import SW_cache from "@/plugins/sw-page-json-builder.ts"; | ||
export default defineConfig({ | ||
plugins: [tailwind()], | ||
plugins: [tailwind(), | ||
// fresh_cache, | ||
SW_cache(), | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Plugin, PluginMiddleware } from "$fresh/server.ts"; | ||
import * as path from "https://deno.land/[email protected]/path/mod.ts"; | ||
import { getFlatSlugs } from "@/utils/course.ts"; | ||
export default function SW_cache( | ||
): Plugin { | ||
let staticDir = path.join(Deno.cwd(), "static"); | ||
const SW_cacheMiddleware: PluginMiddleware = { | ||
path: "/", | ||
middleware: { | ||
handler: async (_, ctx) => { | ||
if (ctx.url.pathname == "/sw-cache.json") { | ||
const resp = new Response(JSON.stringify(await getFlatSlugs()), { | ||
headers: { | ||
"content-type": "application/json", | ||
} | ||
}); | ||
return resp; | ||
} | ||
return ctx.next() | ||
}, | ||
}, | ||
}; | ||
|
||
const middlewares: Plugin["middlewares"] = []; | ||
|
||
return { | ||
name: "sw-cache", | ||
async configResolved(config) { | ||
if (config.dev) { | ||
staticDir = config.staticDir; | ||
middlewares.push(SW_cacheMiddleware); | ||
} | ||
}, | ||
middlewares, | ||
async buildStart(config) { | ||
staticDir = config.staticDir; | ||
console.log("SW_cache buildStart"); | ||
const outFilePath = path.join(staticDir, "sw-cache.json"); | ||
const slugs = await getFlatSlugs(); | ||
const data = JSON.stringify(slugs); | ||
await Deno.writeTextFile(outFilePath, data); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
if ("serviceWorker" in navigator) { | ||
navigator.serviceWorker.register("/sw.js") | ||
navigator.serviceWorker.register("/sw.js", { | ||
type: 'module' | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import { extract } from "https://deno.land/[email protected]/encoding/front_matter.ts" | |
import { Course, CourseAttributes, CourseGroup } from "../utils/types.ts"; | ||
|
||
export let CoursesCount = 0; | ||
export let FlatSlugsCache: string[] = []; | ||
|
||
export async function getGroupJsonData( | ||
groupPath: string, | ||
|
@@ -104,11 +105,16 @@ export async function getCourses( | |
cache.courses = merged; | ||
|
||
const endTime = performance.now(); | ||
console.log(`Caching data took ${(endTime - startTime) / 1000} seconds`); | ||
// console.log(`Caching data took ${(endTime - startTime) / 1000} seconds`); | ||
return cache; | ||
} | ||
|
||
export function getNumberOfCourses(courses: (Course | CourseGroup)[]) { | ||
export async function getFlatSlugs() { | ||
if (FlatSlugsCache.length > 0) { | ||
// console.log("Using cache"); | ||
return FlatSlugsCache; | ||
} | ||
const { courses } = await getCourses(); | ||
const slugs = courses.map((c) => { | ||
if ("courses" in c) { | ||
c.courses.sort((a, b) => a.order - b.order); | ||
|
@@ -117,35 +123,25 @@ export function getNumberOfCourses(courses: (Course | CourseGroup)[]) { | |
return c.slug.replace("\\", "/"); | ||
}); | ||
const FlatSlugs = slugs.flat(); | ||
FlatSlugsCache = FlatSlugs; | ||
return FlatSlugs; | ||
} | ||
export async function getNumberOfCourses() { | ||
const FlatSlugs = await getFlatSlugs(); | ||
return FlatSlugs.length; | ||
} | ||
|
||
export async function findNextCourse(slug: string) { | ||
const { courses } = await getCourses(); | ||
const slugs = courses.map((c) => { | ||
if ("courses" in c) { | ||
c.courses.sort((a, b) => a.order - b.order); | ||
return c.courses.map((c) => c.slug.replace("\\", "/")); | ||
} | ||
return c.slug.replace("\\", "/"); | ||
}); | ||
const FlatSlugs = slugs.flat(); | ||
const FlatSlugs = await getFlatSlugs(); | ||
const index = FlatSlugs.indexOf(slug); | ||
if (index === -1) { | ||
return slug; | ||
} | ||
return FlatSlugs[index + 1]; | ||
} | ||
|
||
export async function findPrevCourse(slug: string) { | ||
const { courses } = await getCourses(); | ||
const slugs = courses.map((c) => { | ||
if ("courses" in c) { | ||
c.courses.sort((a, b) => a.order - b.order); | ||
return c.courses.map((c) => c.slug.replace("\\", "/")); | ||
} | ||
return c.slug.replace("\\", "/"); | ||
}); | ||
const FlatSlugs = slugs.flat(); | ||
const FlatSlugs = await getFlatSlugs(); | ||
const index = FlatSlugs.indexOf(slug); | ||
if (index === 1) { | ||
return slug; | ||
|