remove css plugin

This commit is contained in:
monoid 2023-01-07 02:37:35 +09:00
parent b552553edb
commit 6ce9767e3b
11 changed files with 40 additions and 24 deletions

View File

@ -6,16 +6,24 @@ export function MarkdownRenderer(props: { text: string | undefined }) {
text = ""; text = "";
} }
let c = text; let c = text;
let meta = null;
if (text.startsWith("---")) { if (text.startsWith("---")) {
const index = text.indexOf("\n---", 3); const index = text.indexOf("\n---", 3);
meta = text.slice(4, index);
c = text.slice(index + 4, text.length); c = text.slice(index + 4, text.length);
} }
return ( return (<>
{meta ? <div>
<h2>Meta</h2>
<pre>{meta}</pre>
<hr class="mt-2 mb-2"></hr>
</div> : <div></div>}
<div <div
class="markdown-body" class="markdown-body"
dangerouslySetInnerHTML={{ __html: marked.parse(c) }} dangerouslySetInnerHTML={{ __html: marked.parse(c) }}
> >
</div> </div>
</>
); );
} }

View File

@ -50,7 +50,7 @@ function FetchAndRender(props: { src: string; type: string }) {
} }
} }
export function RenderView(props: { src: string }) { export function RenderView(props: { src: string, mdbase?: string }) {
const src = props.src; const src = props.src;
const type = extToType(extname(src)); const type = extToType(extname(src));
switch (type) { switch (type) {

20
main.ts
View File

@ -6,8 +6,6 @@
import { import {
Manifest, Manifest,
Plugin,
PluginRenderResult,
ServerContext, ServerContext,
StartOptions, StartOptions,
} from "$fresh/server.ts"; } from "$fresh/server.ts";
@ -18,7 +16,6 @@ import twindConfig from "./twind.config.ts";
import "https://deno.land/std@0.170.0/dotenv/load.ts"; import "https://deno.land/std@0.170.0/dotenv/load.ts";
import { Command } from "https://deno.land/x/cliffy@v0.25.6/mod.ts"; import { Command } from "https://deno.land/x/cliffy@v0.25.6/mod.ts";
import { fromFileUrl, join } from "path/mod.ts";
import { prepareSecretKey } from "./util/secret.ts"; import { prepareSecretKey } from "./util/secret.ts";
import { serve } from "http/server.ts"; import { serve } from "http/server.ts";
@ -28,21 +25,6 @@ import { prepareDocs } from "./src/store/doc.ts";
import { connectDB } from "./src/user/db.ts"; import { connectDB } from "./src/user/db.ts";
import * as users from "./src/user/user.ts"; import * as users from "./src/user/user.ts";
const github_markdown = (await Deno.readTextFile(
join(fromFileUrl(import.meta.url), "..", "static", "github-markdown.css"),
)).replaceAll("\n", "");
const CSSPlugin: Plugin = {
name: "css plugin",
render(ctx): PluginRenderResult {
ctx.render();
return {
styles: [{
cssText: github_markdown,
}],
};
},
};
async function startServer(manifest: Manifest, options: StartOptions = {}) { async function startServer(manifest: Manifest, options: StartOptions = {}) {
const ctx = await ServerContext.fromManifest(manifest, options); const ctx = await ServerContext.fromManifest(manifest, options);
@ -63,7 +45,7 @@ async function start(
} = {}, } = {},
) { ) {
await startServer(manifest, { await startServer(manifest, {
plugins: [twindPlugin(twindConfig), CSSPlugin], plugins: [twindPlugin(twindConfig)],
port: port, port: port,
hostname: hostname, hostname: hostname,
}); });

View File

@ -7,6 +7,7 @@ export const handler = async (
req: Request, req: Request,
ctx: MiddlewareHandlerContext<Record<string, unknown>>, ctx: MiddlewareHandlerContext<Record<string, unknown>>,
) => { ) => {
const secret_key = await prepareSecretKey(); const secret_key = await prepareSecretKey();
const cookies = getCookies(req.headers); const cookies = getCookies(req.headers);
const jwt = cookies["auth"]; const jwt = cookies["auth"];

View File

@ -1,5 +1,5 @@
import { HandlerContext, Handlers, PageProps } from "$fresh/server.ts"; import { HandlerContext, Handlers, PageProps } from "$fresh/server.ts";
import { Head } from "$fresh/runtime.ts"; import { asset, Head } from "$fresh/runtime.ts";
import { import {
decodePath, decodePath,
encodePath, encodePath,
@ -61,6 +61,7 @@ async function renderFile(req: Request, path: string) {
} }
} }
} }
const res = await serveFile(req, path, { const res = await serveFile(req, path, {
fileInfo, fileInfo,
}); });
@ -112,6 +113,7 @@ async function renderPage(_req: Request, path: string, ctx: HandlerContext) {
} }
async function GET(req: Request, ctx: HandlerContext): Promise<Response> { async function GET(req: Request, ctx: HandlerContext): Promise<Response> {
const authRequired = Deno.env.get("AUTH_REQUIRED") === "true"; const authRequired = Deno.env.get("AUTH_REQUIRED") === "true";
if (authRequired) { if (authRequired) {
const login = ctx.state["login"]; const login = ctx.state["login"];
@ -192,6 +194,7 @@ export default function DirLists(props: PageProps<DirOrFileProps>) {
<> <>
<Head> <Head>
<title>Simple file server : {data.path}</title> <title>Simple file server : {data.path}</title>
<link rel="stylesheet" href={asset("/github-markdown.css")} />
</Head> </Head>
<div class="p-4 mx-auto max-w-screen-md"> <div class="p-4 mx-auto max-w-screen-md">
{data.type === "dir" {data.type === "dir"

View File

@ -5,6 +5,7 @@ export default function Home() {
<> <>
<Head> <Head>
<title>Simple file server</title> <title>Simple file server</title>
</Head> </Head>
<div class="p-4 mx-auto max-w-screen-md"> <div class="p-4 mx-auto max-w-screen-md">
<img <img

View File

@ -104,6 +104,7 @@
font-size: 16px; font-size: 16px;
line-height: 1.5; line-height: 1.5;
word-wrap: break-word; word-wrap: break-word;
} }
.markdown-body .octicon { .markdown-body .octicon {
@ -1034,3 +1035,10 @@
.markdown-body ::-webkit-calendar-picker-indicator { .markdown-body ::-webkit-calendar-picker-indicator {
filter: invert(50%); filter: invert(50%);
} }
.markdown-body ol{
list-style-type: decimal;
}
.markdown-body ul{
list-style-type: disc;
}

BIN
test_data/a/img.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

View File

@ -12,5 +12,6 @@
</head> </head>
<body> <body>
hello world hello world
<img src="img.jpg"/>
</body> </body>
</html> </html>

View File

@ -4,3 +4,15 @@ tags: ["한글", "테스트"]
--- ---
# 한글 테스트. 띄어쓰기없이도되나? # 한글 테스트. 띄어쓰기없이도되나?
![img](./img.jpg)
1. asdf
2. asdf
3. sdf
* a
* b
* c
* d

BIN
test_data/f/img.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB