From 85afa80eb4b65079ca7795cae21f6d6e63d39eac Mon Sep 17 00:00:00 2001 From: core Date: Fri, 30 Jun 2023 20:38:42 -0400 Subject: [PATCH] some blog work --- package.json | 3 ++ src/lib/PostLayout.svelte | 13 +++++++ src/routes/+layout.svelte | 48 ++++++++++++++++++++++++++ src/routes/blog/blog-test/+page.svelte | 13 +++++++ src/routes/blog/blog-test/page.svx | 29 ++++++++++++++++ svelte.config.js | 48 +++++++++++++++++++++++++- yarn.lock | 45 ++++++++++++++++++++++++ 7 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 src/lib/PostLayout.svelte create mode 100644 src/routes/blog/blog-test/+page.svelte create mode 100644 src/routes/blog/blog-test/page.svx diff --git a/package.json b/package.json index 6727642..3cf4fdf 100644 --- a/package.json +++ b/package.json @@ -14,13 +14,16 @@ "devDependencies": { "@sveltejs/adapter-auto": "^2.0.0", "@sveltejs/kit": "^1.5.0", + "@types/prismjs": "^1.26.0", "@typescript-eslint/eslint-plugin": "^5.45.0", "@typescript-eslint/parser": "^5.45.0", "eslint": "^8.28.0", "eslint-config-prettier": "^8.5.0", "eslint-plugin-svelte": "^2.26.0", + "mdsvex": "^0.11.0", "prettier": "^2.8.0", "prettier-plugin-svelte": "^2.8.1", + "prismjs": "^1.29.0", "svelte": "^3.54.0", "svelte-check": "^3.0.1", "tslib": "^2.4.1", diff --git a/src/lib/PostLayout.svelte b/src/lib/PostLayout.svelte new file mode 100644 index 0000000..1b23acd --- /dev/null +++ b/src/lib/PostLayout.svelte @@ -0,0 +1,13 @@ + + + + {title} - blog - coredoesdev + + +

{title}

+ + + \ No newline at end of file diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 35ce104..dbbb92a 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -1,3 +1,51 @@ + + diff --git a/src/routes/blog/blog-test/+page.svelte b/src/routes/blog/blog-test/+page.svelte new file mode 100644 index 0000000..1c2873c --- /dev/null +++ b/src/routes/blog/blog-test/+page.svelte @@ -0,0 +1,13 @@ + + + + + + + + diff --git a/src/routes/blog/blog-test/page.svx b/src/routes/blog/blog-test/page.svx new file mode 100644 index 0000000..b809f72 --- /dev/null +++ b/src/routes/blog/blog-test/page.svx @@ -0,0 +1,29 @@ +--- +title: Blog Test +published: 2023-06-30T22:22:19+0000 +--- + +# Testing out the blog system + +i wanted to make a new blog lol + +so, uh Ahere we are! + +```rust?lines=2-3 +pub fn code_highlighting() { + // lines can be highlighted + println!("works!"); + // links are converted: https://example.com +} +``` + +Diff's work too: + +```diff-rust +pub fn code_highlighting() { + // lines can be highlighted +- println!("works!"); ++ let foo = 1; + // links are converted: https://example.com +} +``` \ No newline at end of file diff --git a/svelte.config.js b/svelte.config.js index 963127c..db13246 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -1,11 +1,57 @@ import adapter from '@sveltejs/adapter-auto'; import { vitePreprocess } from '@sveltejs/kit/vite'; +import {mdsvex} from "mdsvex"; + +function escapeBraces(unsafe) +{ + return unsafe + .replace(/{/g, "{") + .replace(/}/g, "}"); +} + +function highlighter(code, lang) { + // Lang can be: + // just the lang ('rust') + // the lang, then in brackets lines to hightlight ('rust[1-5,9,21-23]') + + let params = new URLSearchParams(lang.split('?')[1]); + let real_lang = lang.split('?')[0]; + + let classes = [`language-${real_lang}`]; + let props = ""; + + if (params.has("lines")) { + props += `data-line="${params.get("lines")}" `; + } + if (params.has("src")) { + props += `data-src="${params.get("src")}" `; + } + if (params.has("enableDownload")) { + props += "data-download-link "; + } + if (params.has("downloadLabel")) { + props += `data-download-link-label="${params.get("downloadLabel")}" `; + } + + return `
${escapeBraces(code)}
` +} /** @type {import('@sveltejs/kit').Config} */ const config = { // Consult https://kit.svelte.dev/docs/integrations#preprocessors // for more information about preprocessors - preprocess: vitePreprocess(), + preprocess: [ + vitePreprocess(), + mdsvex({ + extensions: ['.svx'], + layout: './src/lib/PostLayout.svelte', + highlight: { + highlighter + } + }) + ], + + extensions: ['.svelte', '.svx'], kit: { // adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list. diff --git a/yarn.lock b/yarn.lock index 778ebde..70d3f81 100644 --- a/yarn.lock +++ b/yarn.lock @@ -268,6 +268,11 @@ resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.12.tgz#d70faba7039d5fca54c83c7dbab41051d2b6f6cb" integrity sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA== +"@types/prismjs@^1.26.0": + version "1.26.0" + resolved "https://registry.yarnpkg.com/@types/prismjs/-/prismjs-1.26.0.tgz#a1c3809b0ad61c62cac6d4e0c56d610c910b7654" + integrity sha512-ZTaqn/qSqUuAq1YwvOFQfVW1AR/oQJlLSZVustdjwI+GZ8kr0MSHBj0tsXPW1EqHubx50gtBEjbPGsdZwQwCjQ== + "@types/pug@^2.0.6": version "2.0.6" resolved "https://registry.yarnpkg.com/@types/pug/-/pug-2.0.6.tgz#f830323c88172e66826d0bde413498b61054b5a6" @@ -278,6 +283,11 @@ resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.0.tgz#591c1ce3a702c45ee15f47a42ade72c2fd78978a" integrity sha512-G8hZ6XJiHnuhQKR7ZmysCeJWE08o8T0AXtk5darsCaTVsYZhhgUrq53jizaR2FvsoeCwJhlmwTjkXBY5Pn/ZHw== +"@types/unist@^2.0.0", "@types/unist@^2.0.2", "@types/unist@^2.0.3": + version "2.0.6" + resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.6.tgz#250a7b16c3b91f672a24552ec64678eeb1d3a08d" + integrity sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ== + "@typescript-eslint/eslint-plugin@^5.45.0": version "5.59.8" resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.59.8.tgz#1e7a3e5318ece22251dfbc5c9c6feeb4793cc509" @@ -1012,6 +1022,16 @@ magic-string@^0.30.0: dependencies: "@jridgewell/sourcemap-codec" "^1.4.13" +mdsvex@^0.11.0: + version "0.11.0" + resolved "https://registry.yarnpkg.com/mdsvex/-/mdsvex-0.11.0.tgz#d6672406abbf341933d60c9bfebd39ffb893f851" + integrity sha512-gJF1s0N2nCmdxcKn8HDn0LKrN8poStqAicp6bBcsKFd/zkUBGLP5e7vnxu+g0pjBbDFOscUyI1mtHz+YK2TCDw== + dependencies: + "@types/unist" "^2.0.3" + prism-svelte "^0.4.7" + prismjs "^1.17.1" + vfile-message "^2.0.4" + merge2@^1.3.0, merge2@^1.4.1: version "1.4.1" resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae" @@ -1196,6 +1216,16 @@ prettier@^2.8.0: resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da" integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q== +prism-svelte@^0.4.7: + version "0.4.7" + resolved "https://registry.yarnpkg.com/prism-svelte/-/prism-svelte-0.4.7.tgz#fbc6709450b4e2ed660ddb82c3718817fc584cbe" + integrity sha512-yABh19CYbM24V7aS7TuPYRNMqthxwbvx6FF/Rw920YbyBWO3tnyPIqRMgHuSVsLmuHkkBS1Akyof463FVdkeDQ== + +prismjs@^1.17.1, prismjs@^1.29.0: + version "1.29.0" + resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.29.0.tgz#f113555a8fa9b57c35e637bba27509dcf802dd12" + integrity sha512-Kx/1w86q/epKcmte75LNrEoT+lX8pBpavuAbvJWRXar7Hz8jrtF+e3vY751p0R8H9HdArwaCTNDDzHg/ScJK1Q== + punycode@^2.1.0: version "2.3.0" resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.3.0.tgz#f67fa67c94da8f4d0cfff981aee4118064199b8f" @@ -1462,6 +1492,13 @@ undici@~5.22.0: dependencies: busboy "^1.6.0" +unist-util-stringify-position@^2.0.0: + version "2.0.3" + resolved "https://registry.yarnpkg.com/unist-util-stringify-position/-/unist-util-stringify-position-2.0.3.tgz#cce3bfa1cdf85ba7375d1d5b17bdc4cada9bd9da" + integrity sha512-3faScn5I+hy9VleOq/qNbAd6pAx7iH5jYBMS9I1HgQVijz/4mv5Bvw5iw1sC/90CODiKo81G/ps8AJrISn687g== + dependencies: + "@types/unist" "^2.0.2" + uri-js@^4.2.2: version "4.4.1" resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.1.tgz#9b1a52595225859e55f669d928f88c6c57f2a77e" @@ -1469,6 +1506,14 @@ uri-js@^4.2.2: dependencies: punycode "^2.1.0" +vfile-message@^2.0.4: + version "2.0.4" + resolved "https://registry.yarnpkg.com/vfile-message/-/vfile-message-2.0.4.tgz#5b43b88171d409eae58477d13f23dd41d52c371a" + integrity sha512-DjssxRGkMvifUOJre00juHoP9DPWuzjxKuMDrhNbk2TdaYYBNMStsNhEOt3idrtI12VQYM/1+iM0KOzXi4pxwQ== + dependencies: + "@types/unist" "^2.0.0" + unist-util-stringify-position "^2.0.0" + vite@^4.3.0: version "4.3.9" resolved "https://registry.yarnpkg.com/vite/-/vite-4.3.9.tgz#db896200c0b1aa13b37cdc35c9e99ee2fdd5f96d"