From d7c16c6763b4e0fa7339e05b4f89182be12a305d Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Wed, 31 Jul 2024 22:24:23 -0400 Subject: [PATCH] Use HLJS, and add the Tomorrow theme. --- bun.lockb | Bin 28248 -> 29014 bytes package.json | 2 ++ src/assets/static/tomorrow.css | 44 +++++++++++++++++++++++++++++++++ src/services/post-file.ts | 17 ++++++++++++- src/templates/Page.tsx | 1 + 5 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/assets/static/tomorrow.css diff --git a/bun.lockb b/bun.lockb index 1d94372d8d6a16a6ba75130ee2b84a001674ff84..703acd8a4e18e8839bdb565cf2216af23b98b2c7 100755 GIT binary patch delta 4386 zcmb_f4Nz3q6~6b$0?SV%vivL%K-8!dmR$i66c!L+`TtP_HPxWt@+1C%QKXU8iN+dZ z#FN%&Y)y)3ow3?crW$P1Xi{w^*feHZn?GwyI*n7cXj>i8sQu1+Z(-YXI!T&4^S$q$ zd(S=h-1E-8@7?!5mKO%(PRr!Wb$PqrZA&{AKe&C-sc+RE=)2i`E8o25!s@B7de3`d z@YdOtLM^kpYhr?r=4rynGpqaCF~;3e2tOfQhr5r)j2$ydh(HK86(Jr09|8w}+gGnx z<7^b-ME8w}UG-=TLgQwG5TW4pYn$4apflTBYySWoj`nk4HZ~p{1upazA{KleJO-Qs z4grq>+rU?Rv~f$|jtO!Q#xa-ZPTa$M!9sMo22ptk9kqJLIJn3Y?gNhl6W9nI52Xlj z54>PUjgTY3A42Ad2f^Im2ObOF4h{pifz9B34{MHhg1LW@Dt8H&0~J=Z>1+aXxau1g zuW=&2t!-M6oiN1V+lpndLl!i1!`yAJxG^y^o*h$pEUUy4WY+M>ArU3N-rT&+&#tvx+E#bH_iCIE-56v z(~JRlnO0~jY{NJMQXwRN+6d`INOQD4-!xf4Lq@ytDP)BMZ3b222Bca@s&B?ZWKgaq zVe~VQ9#==RttMnyBP93$=@UpLY9C8Uh-KBV=0-@{G|7-=^v6r#8Q>p$Uk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FXj#a)gyM8hC3kez()a|(BtFBe7qOT{Z9ex z@aq6KW|p630qt(A&}}VlfUUd$Pfq~L-2P7mfJCF+tr9qpz>Q}+mU+4H!2hNId>j3r z6<}oIb1wj1|6MBpdTyU<0l@z^Vq(MotptXfV?v|pcv_{*A$3V3S(k*-+e<3tN{Vzg z(vKnaJ1eD|Mj^F3!)T$aQWns|u12!E!svb1hPjDwi$mbyQ-%x4!^`XJOWo1ZwM85r zu1;SYgsVI#!u+TFJ=ow*_E1auuZLgF`gW*VgaK&LMf9`c0+hx-?--4hg+RW~psbkY zlw=nifQsvTAHY`;A4oXl|Ll4d^HszZz8~QI%mH$Nc>o`_Nb;6M4RAT(ACkxicoLqY z7$^Z&0i{4WkO<5Nl7M7@OV4Nwcz0c(J@z&fB2!2c%E46FcB0G!q& z{RnS{um$J_dVpS_4|s$lK|4*hl4O}byn9uKlEjzKO27>i030>z7&ka%ZVfb1mO`QB zPHHI6bo91z)`j>WdEf5mmF1m^yx+An&6(yBiS$;vCcQLX-X?caL4_urlu)BN%y+$O ze`{~em6dd%HbY;1hQoYW zfA|jtAC4S(J=8yXE7jC%QqQE^LtbQRh+e6iE}l2ZwN{%Zo-vABrzszYQQ8{2!~D9K zncX=*c~#Vef8u~mpz9SezR3f$zGWDp>67|2#!`)7jc3Egc-GUc+=!sqdb`8?_Grnz zQ@ZkZ6KDO?>+4=>exoFP^hE3%@xinF{l;gE@cg7RCEOzhC;dHvx!Op-LH0a!rT)KW zqZv)dv4okqS3z0{0Q6m=eDzZXJ1KFq$>@7xXJa;G8FKO?;PCmeCN9z zirlq4ZE2dzDY|U5xXHfY(`T*4t2MU+4b7e=~FYm*>U1 d=vtXZ_U6RlhUPudw6J?0ZR`mdzSX^6`4^+P4Y2?K diff --git a/package.json b/package.json index da7cd70..062425e 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,10 @@ }, "dependencies": { "@types/yaml-front-matter": "^4.1.3", + "highlight.js": "^11.10.0", "hono": "^4.4.13", "marked": "^13.0.2", + "marked-highlight": "^2.1.3", "remark": "^15.0.1", "yaml-front-matter": "^4.1.1" }, diff --git a/src/assets/static/tomorrow.css b/src/assets/static/tomorrow.css new file mode 100644 index 0000000..8cf8a38 --- /dev/null +++ b/src/assets/static/tomorrow.css @@ -0,0 +1,44 @@ +/* Tomorrow Theme */ +/* https://jmblog.github.io/color-themes-for-google-code-highlightjs */ +/* Original theme - https://github.com/chriskempson/tomorrow-theme */ +/* https://jmblog.github.io/color-themes-for-google-code-highlightjs */ +.tomorrow-comment, pre .comment, pre .title { + color: #8e908c; +} + +.tomorrow-red, pre .variable, pre .attribute, pre .tag, pre .regexp, pre .ruby .constant, pre .xml .tag .title, pre .xml .pi, pre .xml .doctype, pre .html .doctype, pre .css .id, pre .css .class, pre .css .pseudo { + color: #c82829; +} + +.tomorrow-orange, pre .number, pre .preprocessor, pre .built_in, pre .literal, pre .params, pre .constant { + color: #f5871f; +} + +.tomorrow-yellow, pre .class, pre .ruby .class .title, pre .css .rules .attribute { + color: #eab700; +} + +.tomorrow-green, pre .string, pre .value, pre .inheritance, pre .header, pre .ruby .symbol, pre .xml .cdata { + color: #718c00; +} + +.tomorrow-aqua, pre .css .hexcolor { + color: #3e999f; +} + +.tomorrow-blue, pre .function, pre .python .decorator, pre .python .title, pre .ruby .function .title, pre .ruby .title .keyword, pre .perl .sub, pre .javascript .title, pre .coffeescript .title { + color: #4271ae; +} + +.tomorrow-purple, pre .keyword, pre .javascript .function { + color: #8959a8; +} + +pre code { + display: block; + background: white; + color: #4d4d4c; + line-height: 1.5; + border: 1px solid #ccc; + padding: 10px; +} diff --git a/src/services/post-file.ts b/src/services/post-file.ts index 85098b0..0a23281 100644 --- a/src/services/post-file.ts +++ b/src/services/post-file.ts @@ -2,12 +2,27 @@ import { POST_PATH } from "@blog/config"; import { readdir } from "node:fs/promises"; import type { Post } from "@blog/models/Post"; import * as yamlFront from "yaml-front-matter"; -import { marked } from "marked"; +import { Marked } from "marked"; +import { markedHighlight } from "marked-highlight"; +import hljs from "highlight.js"; + +export function getMarkedInstance(): Marked { + return new Marked( + markedHighlight({ + langPrefix: 'hljs language-', + highlight(code, lang, info) { + const language = hljs.getLanguage(lang) ? lang : 'plaintext'; + return hljs.highlight(code, { language }).value; + } + }) + ) +} export async function readPostFile(path: string): Promise { const file = Bun.file(path); const fileContent = await file.text(); const parsedData = yamlFront.loadFront(fileContent); + const marked: Marked = getMarkedInstance(); const postHtml = await marked.parse(parsedData.__content); let slug = parsedData.slug; diff --git a/src/templates/Page.tsx b/src/templates/Page.tsx index 4b961e3..bc243fc 100644 --- a/src/templates/Page.tsx +++ b/src/templates/Page.tsx @@ -14,6 +14,7 @@ export function Page({ children, meta }: { children: any, meta: SiteMeta }) {