big updats
This commit is contained in:
22
main.ts
22
main.ts
@@ -1,20 +1,20 @@
|
||||
import { serveFile } from "jsr:@std/http/file-server";
|
||||
import { STATUS_TEXT } from "jsr:@std/http/status";
|
||||
import { serveFile } from "@std/http/file-server";
|
||||
import { STATUS_TEXT } from "@std/http/status";
|
||||
import { type App, toValue } from "vue";
|
||||
import { type Router } from "vue-router";
|
||||
import { renderToString } from "vue/server-renderer";
|
||||
import transpileResponse from "./transpile.ts";
|
||||
import { DOMParser } from "jsr:@b-fuze/deno-dom";
|
||||
import { join } from "jsr:@std/path/join";
|
||||
import { exists } from "jsr:@std/fs";
|
||||
import { type DJSSRContext } from "@/useDJSSRContext.ts";
|
||||
import { type DJAPIResult, type DJAPIResultMap } from "@/api.ts";
|
||||
import { DOMParser } from "@b-fuze/deno-dom";
|
||||
import { join } from "@std/path/join";
|
||||
import { exists } from "@std/fs";
|
||||
import { type DjSSRContext } from "@/useDjSSRContext.ts";
|
||||
import { type DjAPIResult, type DjAPIResultMap } from "@/api.ts";
|
||||
|
||||
const utf8Decoder = new TextDecoder("utf-8");
|
||||
|
||||
const parser = new DOMParser();
|
||||
|
||||
function appHeaderScript(params: { ssrContext: DJSSRContext, entryPath: string }) {
|
||||
function appHeaderScript(params: { ssrContext: DjSSRContext, entryPath: string }) {
|
||||
return `
|
||||
<title>${ toValue(params.ssrContext.head.title) }</title>
|
||||
${ toValue(params.ssrContext.head.metatags).map(_ => `<meta name="${ _.name }" content="${ _.content }">`).join('\n\t') }
|
||||
@@ -55,7 +55,7 @@ for await (const path of publicFiles) {
|
||||
}
|
||||
|
||||
async function getAPIResponse(apiReq: Request): Promise<Response> {
|
||||
let jsonResponse: DJAPIResult | { error: string } | null = null;
|
||||
let jsonResponse: DjAPIResult | { error: string } | null = null;
|
||||
let status = 200;
|
||||
|
||||
const pathname = URL.parse(apiReq.url)?.pathname;
|
||||
@@ -76,7 +76,7 @@ async function getAPIResponse(apiReq: Request): Promise<Response> {
|
||||
paths.push(`${contentDir}${dirEnt.name}`);
|
||||
}
|
||||
}
|
||||
const result: DJAPIResultMap['/rp-articles'] = [];
|
||||
const result: DjAPIResultMap['/rp-articles'] = [];
|
||||
for (const filePath of paths) {
|
||||
const content = await Deno.readTextFile(filePath);
|
||||
const dom = parser.parseFromString(content, 'text/html');
|
||||
@@ -197,7 +197,7 @@ Deno.serve({
|
||||
app.provide("dom-parse", (innerHTML: string) => {
|
||||
return parser.parseFromString(innerHTML, "text/html").documentElement;
|
||||
});
|
||||
const ssrContext: DJSSRContext = { styles: {}, registry: {}, head: { title: "", metatags: [] } };
|
||||
const ssrContext: DjSSRContext = { styles: {}, registry: {}, head: { title: "", metatags: [] } };
|
||||
if (router) {
|
||||
await router.replace(pathname.split('/' + baseDirectoryName)[1]);
|
||||
await router.isReady();
|
||||
|
||||
Reference in New Issue
Block a user