From ffedc34675e8854ba87fcf9f861db594c6a20afd Mon Sep 17 00:00:00 2001 From: taskylizard <75871323+taskylizard@users.noreply.github.com> Date: Tue, 14 Nov 2023 22:48:52 +0530 Subject: [PATCH] lint --- .vitepress/constants.ts | 10 +-- .vitepress/hooks/meta.ts | 67 +++++++++++---------- .vitepress/hooks/opengraph.ts | 2 +- .vitepress/hooks/satoriConfig.ts | 4 +- .vitepress/loaders/guides.data.ts | 8 +-- .vitepress/routes/index.post.ts | 2 +- .vitepress/theme/components/Feedback.vue | 6 +- .vitepress/theme/components/Feedback2.vue | 57 ++++++++++++------ .vitepress/theme/components/InputField.vue | 2 +- .vitepress/theme/components/SidebarCard.vue | 6 +- .vitepress/theme/index.ts | 2 +- 11 files changed, 97 insertions(+), 69 deletions(-) diff --git a/.vitepress/constants.ts b/.vitepress/constants.ts index f4b15cb3f..93440e350 100644 --- a/.vitepress/constants.ts +++ b/.vitepress/constants.ts @@ -9,12 +9,14 @@ export const meta = { // Netlify to Cloudflare otherwise dev export const commitRef = process.env.COMMIT_REF - ? `${process.env.COMMIT_REF.slice(0, 8)}` + ? `${process.env.COMMIT_REF.slice(0, 8)}` : process.env.CF_PAGES - ? `${process.env.CF_PAGES_COMMIT_SHA.slice(0, 8)}` - : "dev"; + : "dev"; export const socials: DefaultTheme.SocialLink[] = [ { icon: "github", link: "https://github.com/fmhy/FMHYEdit" }, diff --git a/.vitepress/hooks/meta.ts b/.vitepress/hooks/meta.ts index 2f4242606..7b00fe5d5 100644 --- a/.vitepress/hooks/meta.ts +++ b/.vitepress/hooks/meta.ts @@ -6,28 +6,31 @@ export function generateMeta(context: TransformContext, hostname: string) { const url = `${hostname}/${pageData.relativePath.replace(/((^|\/)index)?\.md$/, "$2")}`; - head.push(["link", { rel: "canonical", href: url }]); - head.push(["meta", { property: "og:url", content: url }]); - head.push(["meta", { name: "twitter:url", content: url }]); - head.push(["meta", { name: "twitter:card", content: "summary_large_image" }]); - - head.push(["meta", { property: "og:title", content: pageData.frontmatter.title }]); - head.push(["meta", { name: "twitter:title", content: pageData.frontmatter.title }]); + head.push( + ["link", { rel: "canonical", href: url }], + ["meta", { property: "og:url", content: url }], + ["meta", { name: "twitter:url", content: url }], + ["meta", { name: "twitter:card", content: "summary_large_image" }], + ["meta", { property: "og:title", content: pageData.frontmatter.title }], + ["meta", { name: "twitter:title", content: pageData.frontmatter.title }], + ); if (pageData.frontmatter.description) { - head.push([ - "meta", - { - property: "og:description", - content: pageData.frontmatter.description, - }, - ]); - head.push([ - "meta", - { - name: "twitter:description", - content: pageData.frontmatter.description, - }, - ]); + head.push( + [ + "meta", + { + property: "og:description", + content: pageData.frontmatter.description, + }, + ], + [ + "meta", + { + name: "twitter:description", + content: pageData.frontmatter.description, + }, + ], + ); } if (pageData.frontmatter.image) { head.push([ @@ -46,17 +49,19 @@ export function generateMeta(context: TransformContext, hostname: string) { ]); } else { const url = pageData.filePath.replace("index.md", "").replace(".md", ""); - const imageUrl = `${url}/__og_image__/og.png`.replace(/\/\//g, "/").replace(/^\//, ""); + const imageUrl = `${url}/__og_image__/og.png`.replaceAll("//", "/").replace(/^\//, ""); - head.push(["meta", { property: "og:image", content: `${hostname}/${imageUrl}` }]); - head.push(["meta", { property: "og:image:width", content: "1200" }]); - head.push(["meta", { property: "og:image:height", content: "628" }]); - head.push(["meta", { property: "og:image:type", content: "image/png" }]); - head.push(["meta", { property: "og:image:alt", content: pageData.frontmatter.title }]); - head.push(["meta", { name: "twitter:image", content: `${hostname}/${imageUrl}` }]); - head.push(["meta", { name: "twitter:image:width", content: "1200" }]); - head.push(["meta", { name: "twitter:image:height", content: "628" }]); - head.push(["meta", { name: "twitter:image:alt", content: pageData.frontmatter.title }]); + head.push( + ["meta", { property: "og:image", content: `${hostname}/${imageUrl}` }], + ["meta", { property: "og:image:width", content: "1200" }], + ["meta", { property: "og:image:height", content: "628" }], + ["meta", { property: "og:image:type", content: "image/png" }], + ["meta", { property: "og:image:alt", content: pageData.frontmatter.title }], + ["meta", { name: "twitter:image", content: `${hostname}/${imageUrl}` }], + ["meta", { name: "twitter:image:width", content: "1200" }], + ["meta", { name: "twitter:image:height", content: "628" }], + ["meta", { name: "twitter:image:alt", content: pageData.frontmatter.title }], + ); } if (pageData.frontmatter.tag) { head.push(["meta", { property: "article:tag", content: pageData.frontmatter.tag }]); diff --git a/.vitepress/hooks/opengraph.ts b/.vitepress/hooks/opengraph.ts index 719fd5093..9e10b900a 100644 --- a/.vitepress/hooks/opengraph.ts +++ b/.vitepress/hooks/opengraph.ts @@ -80,7 +80,7 @@ async function generateImage({ page, template, outDir, fonts }: GenerateImagesOp const render = await renderAsync(svg); - const outputFolder = resolve(outDir, url.substring(1), "__og_image__"); + const outputFolder = resolve(outDir, url.slice(1), "__og_image__"); const outputFile = resolve(outputFolder, "og.png"); await mkdir(outputFolder, { recursive: true }); diff --git a/.vitepress/hooks/satoriConfig.ts b/.vitepress/hooks/satoriConfig.ts index 9a3061299..e106e8c7d 100644 --- a/.vitepress/hooks/satoriConfig.ts +++ b/.vitepress/hooks/satoriConfig.ts @@ -1,7 +1,9 @@ import { readFile } from "node:fs/promises"; import { dirname, resolve } from "node:path"; import { fileURLToPath } from "node:url"; -import { SatoriOptions, defineSatoriConfig } from "x-satori/vue"; +import type { SatoriOptions } from "x-satori/vue"; +import { defineSatoriConfig } from "x-satori/vue"; + const __dirname = dirname(fileURLToPath(import.meta.url)); const __fonts = resolve(__dirname, "../fonts"); diff --git a/.vitepress/loaders/guides.data.ts b/.vitepress/loaders/guides.data.ts index 0c60e45e4..2f5270eee 100644 --- a/.vitepress/loaders/guides.data.ts +++ b/.vitepress/loaders/guides.data.ts @@ -1,5 +1,5 @@ +import { writeFile, readFile } from "node:fs/promises"; import { defineLoader } from "vitepress"; -import { writeFile, readFile } from "fs/promises"; interface Data { title?: string; @@ -10,7 +10,7 @@ declare const data: Data; export { data }; const page = "https://rentry.co/fmhy-guides/raw"; -const regex = /\* \[([^\]]+)\]\(([^)]+)\)/g; +const regex = /\* \[([^\]]+)]\(([^)]+)\)/g; const rentryRe = /(?<=rentry\.(co|org)).*/; const guides = new Set(); @@ -29,8 +29,8 @@ export default defineLoader({ const title = match[1]; const url = match[2]; // Fetch rentry guides - if (url.match(rentryRe)) { - const content = await f(url + "/raw"); + if (rentryRe.test(url)) { + const content = await f(`${url}/raw`); guides.add({ title, content }); } else { // Everything else can be here diff --git a/.vitepress/routes/index.post.ts b/.vitepress/routes/index.post.ts index 27515c312..2d0896af2 100644 --- a/.vitepress/routes/index.post.ts +++ b/.vitepress/routes/index.post.ts @@ -37,7 +37,7 @@ export default defineEventHandler(async (event) => { { color: 3447003, title: getFeedbackOption(type).label, - description: description, + description, }, ], }) diff --git a/.vitepress/theme/components/Feedback.vue b/.vitepress/theme/components/Feedback.vue index 50680c870..d3844cca2 100644 --- a/.vitepress/theme/components/Feedback.vue +++ b/.vitepress/theme/components/Feedback.vue @@ -1,8 +1,8 @@