Skip to content

Commit

Permalink
update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
tsar-boomba committed Feb 18, 2024
1 parent c69fe20 commit bc9ae3f
Show file tree
Hide file tree
Showing 11 changed files with 5,433 additions and 3,695 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ jobs:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2.2.2
with:
version: 7.17.0
version: 8.15.3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "16"
node-version: "20"
cache: "pnpm"
- name: Build
run: |
Expand Down
43 changes: 33 additions & 10 deletions astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,42 @@ import robotsTxt from 'astro-robots-txt';
// plugin in separate file don't work 🤷
import type { Plugin } from 'unified';
import type { Root } from 'mdast';
import { getHighlighter, Lang } from 'shiki';
import type { Highlighter } from 'shiki';
import { createCssVariablesTheme, getHighlighter } from 'shiki';
import type { Highlighter, BuiltinLanguage } from 'shiki';
import { visit } from 'unist-util-visit';

const SUPPORTED_LANGS = [
'javascript',
'typescript',
'tsx',
'jsx',
'rust',
'json',
'toml',
'md',
'mdx',
'astro',
] as const satisfies BuiltinLanguage[];

type BlockParams = {
file?: string;
noBadge?: boolean;
};

const myTheme = createCssVariablesTheme({
name: 'css-variables',
variablePrefix: '--shiki-',
variableDefaults: {},
fontStyle: true,
});

let highlighterCache: Promise<Highlighter>;
const parseLangRe = /(?=(?:file=(?<file>\S*))?)(?=(?:noBadge=(?<noBadge>true|false))?)/g;
export const remarkCustomCodeBlock: () => Promise<Plugin<any[], Root>> = async () => {
if (!highlighterCache)
highlighterCache = getHighlighter({
theme: 'css-variables',
themes: [myTheme],
langs: SUPPORTED_LANGS,
});
const highlighter = await highlighterCache;

Expand All @@ -38,7 +59,7 @@ export const remarkCustomCodeBlock: () => Promise<Plugin<any[], Root>> = async (

const { file, noBadge = false } = metaMatch.groups as unknown as BlockParams;

const langColorMap: { [K in Lang]?: { bg: string; fg: string } } = {
const langColorMap: { [K in BuiltinLanguage]?: { bg: string; fg: string } } = {
css: { bg: '#264de4', fg: '#fff' },
ts: { bg: '#007acc', fg: '#fff' },
tsx: { bg: '#007acc', fg: '#fff' },
Expand All @@ -48,16 +69,19 @@ export const remarkCustomCodeBlock: () => Promise<Plugin<any[], Root>> = async (
toml: { bg: '#9c4221', fg: '#fff' },
};

const lang: Lang = (() => {
const lang = rawLang as Lang;
const lang: BuiltinLanguage = (() => {
const lang = rawLang as BuiltinLanguage;

if (lang === 'typescript') return 'ts';
if (lang === 'javascript') return 'js';
if (lang === 'rs') return 'rust';
return lang;
})();

let codeHtml: string = highlighter.codeToHtml(node.value, { lang });
let codeHtml: string = highlighter.codeToHtml(node.value, {
lang,
theme: 'css-variables',
});
if (file) {
codeHtml = codeHtml.replace(`shiki`, `shiki shiki-with-file-name`);
}
Expand All @@ -70,8 +94,8 @@ export const remarkCustomCodeBlock: () => Promise<Plugin<any[], Root>> = async (
? `<div
class='language-badge'
style='background-color:${langColorMap[lang]?.bg ?? '#888'};color:${
langColorMap[lang]?.fg ?? '#fff'
}'
langColorMap[lang]?.fg ?? '#fff'
}'
>
${lang.toUpperCase()}
</div>`
Expand Down Expand Up @@ -110,7 +134,6 @@ export default defineConfig({
],
markdown: {
syntaxHighlight: false,
extendDefaultPlugins: true,
remarkPlugins: [await remarkCustomCodeBlock()],
},
});
54 changes: 28 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,36 @@
"astro": "astro"
},
"devDependencies": {
"@astrojs/mdx": "0.11.6",
"@astrojs/sitemap": "1.0.0",
"@types/mdast": "3.0.10",
"@typescript-eslint/eslint-plugin": "5.42.0",
"@typescript-eslint/parser": "5.42.0",
"astro": "1.6.10",
"astro-compress": "1.1.7",
"astro-robots-txt": "^0.3.10",
"autoprefixer": "10.4.13",
"cssnano": "5.1.14",
"eslint": "8.26.0",
"eslint-config-prettier": "8.5.0",
"eslint-mdx": "2.0.5",
"eslint-plugin-astro": "0.21.0",
"eslint-plugin-jsx-a11y": "6.6.1",
"eslint-plugin-mdx": "2.0.5",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-react": "^7.31.11",
"@astrojs/mdx": "2.1.1",
"@astrojs/sitemap": "3.0.5",
"@types/mdast": "4.0.3",
"@typescript-eslint/eslint-plugin": "7.0.1",
"@typescript-eslint/parser": "7.0.1",
"astro": "4.4.0",
"astro-compress": "2.2.10",
"astro-robots-txt": "1.0.0",
"autoprefixer": "10.4.17",
"cssnano": "6.0.3",
"eslint": "8.56.0",
"eslint-config-prettier": "9.1.0",
"eslint-mdx": "3.1.5",
"eslint-plugin-astro": "0.31.4",
"eslint-plugin-jsx-a11y": "6.8.0",
"eslint-plugin-mdx": "3.1.5",
"eslint-plugin-prettier": "5.1.3",
"eslint-plugin-react": "7.33.2",
"mdast": "3.0.0",
"postcss-preset-env": "7.8.2",
"prettier": "2.7.1",
"sass": "1.55.0",
"shiki": "0.11.1",
"svgo": "2.8.0",
"unified": "10.1.2",
"unist-util-visit": "^4.1.1"
"postcss-preset-env": "9.3.0",
"prettier": "3.2.5",
"sass": "1.71.0",
"shiki": "1.1.3",
"svgo": "3.2.0",
"unified": "11.0.4",
"@astrojs/check": "^0.5.4",
"unist-util-visit": "5.0.0"
},
"dependencies": {
"astro-icon": "0.8.0"
"astro-icon": "1.1.0",
"typescript": "^5.3.3"
}
}
Loading

0 comments on commit bc9ae3f

Please sign in to comment.