-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ability to have a user defined index, with blogindex available …
…at /blog
- Loading branch information
Showing
11 changed files
with
173 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"lock": false, | ||
"tasks": { | ||
"start": "deno run -A --watch=static/,routes/ dev.ts", | ||
"update": "deno run -A -r https://fresh.deno.dev/update ." | ||
}, | ||
"imports": { | ||
"$fresh/": "https://deno.land/x/fresh@1.3.1/", | ||
"preact": "https://esm.sh/preact@10.15.1", | ||
"preact/": "https://esm.sh/preact@10.15.1/", | ||
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.0", | ||
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.3", | ||
"@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.2.3", | ||
"twind": "https://esm.sh/twind@0.16.19", | ||
"twind/": "https://esm.sh/twind@0.16.19/", | ||
"$std/": "https://deno.land/std@0.193.0/" | ||
}, | ||
"compilerOptions": { | ||
"jsx": "react-jsx", | ||
"jsxImportSource": "preact" | ||
}, | ||
"lint": { | ||
"rules": { | ||
"tags": [ | ||
"fresh", | ||
"recommended" | ||
] | ||
} | ||
} | ||
} |
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,5 @@ | ||
#!/usr/bin/env -S deno run -A --watch=static/,routes/ | ||
|
||
import dev from "$fresh/dev.ts"; | ||
|
||
await dev(import.meta.url, "./main.ts"); |
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,15 @@ | ||
// DO NOT EDIT. This file is generated by fresh. | ||
// This file SHOULD be checked into source version control. | ||
// This file is automatically updated during development when running `dev.ts`. | ||
|
||
import * as $0 from "./routes/index.tsx"; | ||
|
||
const manifest = { | ||
routes: { | ||
"./routes/index.tsx": $0, | ||
}, | ||
islands: {}, | ||
baseUrl: import.meta.url, | ||
}; | ||
|
||
export default manifest; |
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,12 @@ | ||
import { BlogOptions } from "../../mod.ts"; | ||
|
||
export default { | ||
title: "Demo Blog", | ||
navbarItems: { | ||
Blog: "/blog", | ||
Archive: "/archive", | ||
}, | ||
rootPath: import.meta.url, | ||
postsPerPage: 5, | ||
useSeparateIndex: true, | ||
} as BlogOptions; |
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,20 @@ | ||
/// <reference no-default-lib="true" /> | ||
/// <reference lib="dom" /> | ||
/// <reference lib="dom.iterable" /> | ||
/// <reference lib="dom.asynciterable" /> | ||
/// <reference lib="deno.ns" /> | ||
|
||
import "$std/dotenv/load.ts"; | ||
|
||
import { start } from "$fresh/server.ts"; | ||
import manifest from "./fresh.gen.ts"; | ||
|
||
import twindPlugin from "$fresh/plugins/twind.ts"; | ||
import twindConfig from "./twind.config.ts"; | ||
|
||
import { blogPlugin } from "../../src/plugin/blog.ts"; | ||
import localConfig from "./local.config.ts"; | ||
|
||
await start(manifest, { | ||
plugins: [twindPlugin(twindConfig), blogPlugin(localConfig)], | ||
}); |
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,11 @@ | ||
import { FreshOptions } from "$fresh/server.ts"; | ||
|
||
export default { | ||
async render(_ctx, render) { | ||
await new Promise<void>((r) => r()); | ||
const body = render(); | ||
if (typeof body !== "string") { | ||
throw new Error("body is missing"); | ||
} | ||
}, | ||
} as FreshOptions; |
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,11 @@ | ||
--- | ||
title: "Single Tag" | ||
date: 2023-8-15 | ||
author: Some Author | ||
--- | ||
|
||
The blog isn't the primary purpose of this site. | ||
|
||
<!--more--> | ||
|
||
Some extra content, just in case. |
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,12 @@ | ||
import { PageProps, RouteContext } from "$fresh/server.ts"; | ||
|
||
export default function Home(_req: Request, _ctx: RouteContext) { | ||
return ( | ||
<div> | ||
<h1> | ||
Welcome to the site! The blog isn't the main purpose here, so we're | ||
using the <pre>useSeparateIndex</pre> option. | ||
</h1> | ||
</div> | ||
); | ||
} |
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,5 @@ | ||
import { Options } from "$fresh/plugins/twind.ts"; | ||
|
||
export default { | ||
selfURL: import.meta.url, | ||
} as Options; |
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,50 @@ | ||
import blogConfig from "./separate_index_fixture/local.config.ts"; | ||
import { createHandler } from "../deps.ts"; | ||
import { assertEquals, assertStringIncludes, DOMParser } from "./test_deps.ts"; | ||
import manifest from "./separate_index_fixture/fresh.gen.ts"; | ||
import { blogPlugin } from "../src/plugin/blog.ts"; | ||
|
||
Deno.test("index page isn't blog", async () => { | ||
//@ts-ignore this will be fixed in fresh 1.4 | ||
const handler = await createHandler(manifest, { | ||
plugins: [blogPlugin(blogConfig)], | ||
}); | ||
const resp = await handler( | ||
new Request("http://127.0.0.1/"), | ||
); | ||
const body = await resp.text(); | ||
assertStringIncludes( | ||
body, | ||
"Welcome to the site! The blog isn't the main purpose here", | ||
); | ||
}); | ||
|
||
Deno.test("blog page is blog", async () => { | ||
//@ts-ignore this will be fixed in fresh 1.4 | ||
const handler = await createHandler(manifest, { | ||
plugins: [blogPlugin(blogConfig)], | ||
}); | ||
const resp = await handler( | ||
new Request("http://127.0.0.1/blog"), | ||
); | ||
const body = await resp.text(); | ||
const doc = new DOMParser().parseFromString(body, "text/html")!; | ||
const postElements = Array.from(doc.querySelectorAll('div[id^="post:"]')); | ||
|
||
assertEquals(postElements.length, 1); | ||
}); | ||
|
||
Deno.test("blog can view posts", async () => { | ||
//@ts-ignore this will be fixed in fresh 1.4 | ||
const handler = await createHandler(manifest, { | ||
plugins: [blogPlugin(blogConfig)], | ||
}); | ||
const resp = await handler( | ||
new Request("http://127.0.0.1/blog/boring-post"), | ||
); | ||
const body = await resp.text(); | ||
assertStringIncludes( | ||
body, | ||
"Some extra content, just in case.", | ||
); | ||
}); |