Skip to content

Commit

Permalink
Merge remote-tracking branch 'template/main' into upgrade_blog
Browse files Browse the repository at this point in the history
  • Loading branch information
gaelgoth committed Sep 6, 2023
2 parents f33db79 + 67878c7 commit 6d1b338
Show file tree
Hide file tree
Showing 11 changed files with 1,878 additions and 1,599 deletions.
37 changes: 27 additions & 10 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
{
"root": true,
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:svelte/recommended",
"prettier"
],
"parser": "@typescript-eslint/parser",
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"],
"plugins": ["svelte3", "@typescript-eslint"],
"ignorePatterns": ["*.cjs"],
"overrides": [{ "files": ["*.svelte"], "processor": "svelte3/svelte3" }],
"settings": {
"svelte3/typescript": true
},
"plugins": [
"@typescript-eslint",
"svelte"
],
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2019
"ecmaVersion": 2020,
"extraFileExtensions": [
".svelte"
]
},
"env": {
"browser": true,
"es2017": true,
"node": true
}
}
},
"overrides": [
{
"files": [
"*.svelte"
],
"parser": "svelte-eslint-parser",
"parserOptions": {
"parser": "@typescript-eslint/parser"
}
}
]
}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ pnpm-debug.log*
src/routes/**/+page.svelte.md
src/routes/**/+page.md
src/static
*.config.js
urara.js
18 changes: 16 additions & 2 deletions .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,19 @@
"trailingComma": "none",
"bracketSpacing": true,
"bracketSameLine": true,
"htmlWhitespaceSensitivity": "ignore"
}
"htmlWhitespaceSensitivity": "ignore",
"plugins": [
"prettier-plugin-svelte"
],
"pluginSearchDirs": [
"."
],
"overrides": [
{
"files": "*.svelte",
"options": {
"parser": "svelte"
}
}
]
}
68 changes: 30 additions & 38 deletions mdsvex.config.ts → mdsvex.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

// mdsvex config type
import type { MdsvexOptions } from 'mdsvex'

// rehype plugins
import rehypeSlug from 'rehype-slug'
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
import rehypeExternalLinks from 'rehype-external-links'

// urara remark plugins
import type { Node, Data } from 'unist'
import { parse, join } from 'node:path'
import { visit } from 'unist-util-visit'
import { toString } from 'mdast-util-to-string'
Expand All @@ -24,41 +18,42 @@ import { renderCodeToHTML, runTwoSlash, createShikiHighlighter } from 'shiki-two

const remarkUraraFm =
() =>
(tree: Node<Data>, { data, filename }: { data: { fm?: Record<string, unknown> }; filename?: string }) => {
const filepath = filename ? filename.split('/src/routes')[1] : 'unknown'
const { dir, name } = parse(filepath)
if (!data.fm) data.fm = {}
// Generate slug & path
data.fm.slug = filepath
data.fm.path = join(dir, `/${name}`.replace('/+page', '').replace('.svelte', ''))
// Generate ToC
if (data.fm.toc !== false) {
const [slugs, toc]: [slugs: Slugger, toc: { depth: number; title: string; slug: string }[]] = [new Slugger(), []]
visit(tree, 'heading', (node: { depth: number }) => {
toc.push({
depth: node.depth,
title: toString(node),
slug: slugs.slug(toString(node), false)
})
(tree, { data, filename }) => {
const filepath = filename ? filename.split('/src/routes')[1] : 'unknown'
const { dir, name } = parse(filepath)
if (!data.fm) data.fm = {}
// Generate slug & path
data.fm.slug = filepath
data.fm.path = join(dir, `/${name}`.replace('/+page', '').replace('.svelte', ''))
// Generate ToC
if (data.fm.toc !== false) {
const [slugs, toc] = [new Slugger(), []]
visit(tree, 'heading', node => {
toc.push({
depth: node.depth,
title: toString(node),
slug: slugs.slug(toString(node), false)
})
if (toc.length > 0) data.fm.toc = toc
else data.fm.toc = false
}
})
if (toc.length > 0) data.fm.toc = toc
else data.fm.toc = false
}
}

// Better type definitions needed
const remarkUraraSpoiler = () => (tree: Node<Data>) =>
visit(tree, 'paragraph', (node: any) => {
const remarkUraraSpoiler = () => tree =>
visit(tree, 'paragraph', node => {
const { children } = node
const text = children[0].value
const re = /\|\|(.{1,}?)\|\|/g
if (re.test(children[0].value)) {
children[0].type = 'html'
children[0].value = text.replace(re, (_match: unknown, p1: string) => `<span class="spoiler">${p1}</span>`)
children[0].value = text.replace(re, (_match, p1) => `<span class="spoiler">${p1}</span>`)
}
return node
})

/** @type {import("mdsvex").MdsvexOptions} */
export default {
extensions: ['.svelte.md', '.md'],
smartypants: {
Expand All @@ -69,18 +64,17 @@ export default {
},
highlight: {
highlighter: async (code, lang, meta) => {
let fence: any
let twoslash: any
let fence, twoslash
try {
fence = parseFence(lex([lang, meta].filter(Boolean).join(' ')))
} catch (error) {
throw new Error(`Could not parse the codefence for this code sample \n${code}`)
}
if (fence?.twoslash === true) twoslash = runTwoSlash(code, lang as string)
if (fence?.twoslash === true) twoslash = runTwoSlash(code, lang)
return `{@html \`${escapeSvelte(
renderCodeToHTML(
code,
lang as string,
lang,
fence ?? {},
{ themeName: 'material-default' },
await createShikiHighlighter({ theme: 'material-default' }),
Expand All @@ -97,12 +91,12 @@ export default {
target: 'mdsvex',
autofill: {
provider: 'fs',
path: (path: string) => path.replace('/src/routes/', '/urara/')
path: path => path.replace('/src/routes/', '/urara/')
},
strict: {
media: {
type: 'string',
array: false,
array: false
}
}
}
Expand All @@ -112,7 +106,7 @@ export default {
[remarkFootnotes, { inlineNotes: true }]
],
rehypePlugins: [
rehypeSlug as any,
rehypeSlug,
[rehypeAutolinkHeadings, { behavior: 'wrap' }],
[
rehypeExternalLinks,
Expand All @@ -122,6 +116,4 @@ export default {
}
]
]
} as MdsvexOptions

/* eslint-enable @typescript-eslint/no-explicit-any */
}
57 changes: 29 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,63 +15,64 @@
"urara:watch": "node urara.js watch",
"kit:dev": "cross-env NODE_OPTIONS=--max_old_space_size=7680 vite dev",
"kit:build": "cross-env NODE_OPTIONS=--max_old_space_size=7680 vite build",
"dev:parallel": "npm-run-all -p -r tsc:watch urara:watch \"kit:dev {@} \" --",
"dev": "npm-run-all -s tsc \"dev:parallel {@} \" --",
"build": "npm-run-all -s tsc urara:build kit:build clean",
"dev:parallel": "run-p -r tsc:watch urara:watch \"kit:dev {@} \" --",
"dev": "run-s tsc \"dev:parallel {@} \" --",
"build": "run-s tsc urara:build kit:build clean",
"preview": "vite preview",
"check": "svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check --plugin-search-dir=. . && eslint --ignore-path .gitignore .",
"format": "prettier --write --plugin-search-dir=. ."
},
"devDependencies": {
"@iconify-json/heroicons-outline": "^1.1.6",
"@iconify-json/heroicons-solid": "^1.1.7",
"@sveltejs/adapter-netlify": "^2.0.7",
"@sveltejs/adapter-static": "^2.0.2",
"@iconify-json/heroicons-outline": "^1.1.7",
"@iconify-json/heroicons-solid": "^1.1.8",
"@sveltejs/adapter-netlify": "^2.0.8",
"@sveltejs/adapter-static": "^2.0.3",
"@sveltejs/adapter-vercel": "^2.4.3",
"@sveltejs/kit": "^1.19.0",
"@sveltejs/kit": "^1.23.0",
"@tailwindcss/typography": "^0.5.9",
"@types/node": "^20.2.5",
"@types/unist": "^2.0.6",
"@typescript-eslint/eslint-plugin": "^5.59.7",
"@typescript-eslint/parser": "^5.59.7",
"@unocss/extractor-svelte": "^0.52.4",
"@types/node": "^20.5.7",
"@types/unist": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^6.4.1",
"@typescript-eslint/parser": "^6.4.1",
"@unocss/extractor-svelte": "^0.55.3",
"@vite-pwa/sveltekit": "^0.1.3",
"chalk": "^5.2.0",
"chalk": "^5.3.0",
"chokidar": "^3.5.3",
"cross-env": "^7.0.3",
"daisyui": "^2.51.6",
"eslint": "^8.41.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-svelte3": "^4.0.0",
"daisyui": "^3.6.3",
"eslint": "^8.48.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-svelte": "^2.33.0",
"fenceparser": "^2.2.0",
"fff-flavored-frontmatter": "1.0.0-alpha.1",
"github-slugger": "^2.0.0",
"mdast-util-to-string": "^3.2.0",
"mdsvex": "^0.10.6",
"mdsvex": "^0.11.0",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.23",
"postcss": "^8.4.28",
"postcss-lightningcss": "^0.7.0",
"prettier": "^2.8.8",
"prettier-plugin-svelte": "^2.10.0",
"prettier": "^3.0.2",
"prettier-plugin-svelte": "^3.0.3",
"rehype-autolink-headings": "^6.1.1",
"rehype-external-links": "^2.1.0",
"rehype-slug": "^5.1.0",
"remark": "^14.0.3",
"remark-fff": "1.0.0-alpha.1",
"remark-footnotes": "~2.0.0",
"shiki-twoslash": "^3.1.2",
"svelte": "^3.59.1",
"svelte-check": "^3.4.3",
"svelte": "^4.2.0",
"svelte-check": "^3.5.0",
"svelte-eslint-parser": "^0.33.0",
"svelte-preprocess": "^5.0.4",
"sveltekit-embed": "^0.0.13",
"tailwindcss": "^3.3.2",
"tslib": "^2.5.2",
"tailwindcss": "^3.3.3",
"tslib": "^2.6.2",
"typescript": "^4.9.5",
"unist-util-visit": "^4.1.2",
"unocss": "^0.52.4",
"vite": "^4.3.9",
"unocss": "^0.55.3",
"vite": "^4.4.9",
"vite-imagetools": "^4.0.19",
"vite-plugin-pwa": "^0.14.7",
"workbox-build": "^6.6.0",
Expand Down
Loading

0 comments on commit 6d1b338

Please sign in to comment.