Skip to content

Commit 0a1b2f6

Browse files
committed
Optimizing the load of shiki
1 parent a5fdd77 commit 0a1b2f6

File tree

130 files changed

+69383
-15254
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+69383
-15254
lines changed

components/Docs/CodeHighlighting.tsx

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
2-
import * as shiki from 'shiki';
32
import { Children, useMemo } from 'react';
43
import { CopyButton } from './CopyButton';
4+
import { ShikiService } from '../../services/ShikiService';
55

66
export interface ICodeHighlightingProps {
77
className?: string;
@@ -77,32 +77,33 @@ const CodePanel = ({ annotation, children, ...props }: React.PropsWithChildren<I
7777
export const CodeHighlighting: React.FunctionComponent<ICodeHighlightingProps> = ({ className, children, ...props }: React.PropsWithChildren<ICodeHighlightingProps>) => {
7878
const [code, setCode] = React.useState('');
7979

80-
React.useEffect(() => {
81-
if (className && children) {
82-
const language = className.split('-')[1];
80+
const fetchHighlighter = async (className: string, children: React.ReactNode) => {
81+
const language = className.split('-')[1];
82+
const highlighter = await ShikiService.getHighlighter();
8383

84-
shiki.setCDN(`../../`);
84+
if (highlighter && children) {
85+
let code = children.toString();
86+
if (code.endsWith(`\n`)) {
87+
code = code.slice(0, -1);
88+
}
8589

86-
shiki.getHighlighter({
87-
langs: [language as any],
88-
theme: `the-unnamed`
89-
}).then((highlighter: shiki.Highlighter) => {
90-
let code = children.toString();
91-
if (code.endsWith(`\n`)) {
92-
code = code.slice(0, -1);
93-
}
90+
setCode(
91+
highlighter.codeToHtml(code, {
92+
lang: getLanguage(className)
93+
})
94+
);
9495

95-
setCode(
96-
highlighter.codeToHtml(code, {
97-
lang: getLanguage(className)
98-
})
99-
);
100-
})
101-
.then(() => {
102-
if (location.hash) {
103-
location.href = location.href;
104-
}
105-
});
96+
if (location.hash) {
97+
location.href = location.href;
98+
}
99+
100+
return;
101+
}
102+
};
103+
104+
React.useEffect(() => {
105+
if (className && children) {
106+
fetchHighlighter(className, children);
106107
}
107108
}, [className, children]);
108109

components/Docs/Markdown.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import rehypeRaw from 'rehype-raw';
77
import remarkGfm from 'remark-gfm';
88
import { CodeBlock, CodeHighlighting } from './CodeHighlighting';
99
import { mdxAnnotations } from 'mdx-annotations';
10+
import { ShikiService } from '../../services/ShikiService';
1011

1112
export interface IMarkdownProps {
1213
content: string | undefined;
1314
slug: string | undefined;
1415
}
1516

1617
export const Markdown: React.FunctionComponent<IMarkdownProps> = ({ content, slug }: React.PropsWithChildren<IMarkdownProps>) => {
18+
const [isReady, setIsReady] = React.useState<boolean>(false);
1719

1820
const getTitle = (props: any) => {
1921
const title = props?.children.length > 0 ? `${props?.children[0] as string}` : "";
@@ -33,6 +35,14 @@ export const Markdown: React.FunctionComponent<IMarkdownProps> = ({ content, slu
3335
);
3436
};
3537

38+
useEffect(() => {
39+
if (content) {
40+
ShikiService.getHighlighter().then((highlighter) => {
41+
setIsReady(true);
42+
});
43+
}
44+
}, [content])
45+
3646
useEffect(() => {
3747
const elms = document.querySelectorAll('blockquote > p > strong');
3848
for (let i = 0; i < elms.length; i++) {
@@ -43,7 +53,8 @@ export const Markdown: React.FunctionComponent<IMarkdownProps> = ({ content, slu
4353
}
4454
}, []);
4555

46-
if (!content) {
56+
57+
if (!content || !isReady) {
4758
return null;
4859
}
4960

content/changelog/CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,37 @@
44

55
### ✨ New features
66

7+
- Localization implemented for the whole extension
8+
79
### 🎨 Enhancements
810

11+
- [#273](https://github.com/estruyf/vscode-front-matter/issues/273): Allow single value arrays to be set as a string with the `singleValueAsString` field property
912
- [#686](https://github.com/estruyf/vscode-front-matter/issues/686): Allow script authors to ask questions during script execution
1013
- [#688](https://github.com/estruyf/vscode-front-matter/issues/688): Allow to show the scheduled articles in the content dashboard (filter and group)
14+
- [#690](https://github.com/estruyf/vscode-front-matter/issues/690): Added the ability to filter values in the `contentRelationship` field
15+
- [#700](https://github.com/estruyf/vscode-front-matter/issues/700): Added the `{{pathToken.relPath}}` placeholder for the `previewPath` property
1116

1217
### ⚡️ Optimizations
1318

1419
- Dashboard layout grid optimizations
20+
- Added the content-type name to the metadata section in the panel
21+
- New implementation of the combobox for the `contentRelationship` field
1522

1623
### 🐞 Fixes
1724

1825
- [#685](https://github.com/estruyf/vscode-front-matter/issues/685): Fix when using non-string values in the tag picker
1926
- [#691](https://github.com/estruyf/vscode-front-matter/issues/691): Silent authentication retrieval for GitHub sponsors
27+
- [#694](https://github.com/estruyf/vscode-front-matter/issues/694): Start terminal session from the folder where the `frontmatter.json` file is located
28+
- [#696](https://github.com/estruyf/vscode-front-matter/issues/696): Close the local server terminal on restart
29+
- [#699](https://github.com/estruyf/vscode-front-matter/issues/699): Changing border theme variable for the dashboard header
30+
- [#703](https://github.com/estruyf/vscode-front-matter/issues/703): Fix retrieval of Astro Collections for `pnpm` projects
31+
- [#704](https://github.com/estruyf/vscode-front-matter/issues/704): Fix `zod` schema script for optional fields
32+
33+
## [9.3.1] - 2023-10-27
34+
35+
### 🐞 Fixes
36+
37+
- [#697](https://github.com/estruyf/vscode-front-matter/issues/697): Fix missing localization key
2038

2139
## [9.3.0] - 2023-10-06 - [Release notes](https://beta.frontmatter.codes/updates/v9.3.0)
2240

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"remark-gfm": "^3.0.1",
4040
"remark-heading-id": "1.0.0",
4141
"scroll-out": "^2.2.12",
42-
"shiki": "^0.14.1",
42+
"shiki": "^0.14.5",
4343
"zustand": "^4.1.5"
4444
},
4545
"devDependencies": {

public/config/content.pagefolders.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "http://json-schema.org/draft-07/schema",
33
"$id": "https://beta.frontmatter.codes/config/content.pagefolders.schema.json",
44
"description": "Defines the settings for Front Matter page folder",
5-
"lastModified": "2023-10-24T09:28:57.205Z",
5+
"lastModified": "2023-11-12T01:41:30.154Z",
66
"type": "object",
77
"title": "Front Matter - page folder",
88
"properties": {

public/config/content.placeholders.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "http://json-schema.org/draft-07/schema",
33
"$id": "https://beta.frontmatter.codes/config/content.placeholders.schema.json",
44
"description": "Defines the settings for Front Matter placeholder",
5-
"lastModified": "2023-10-24T09:28:57.206Z",
5+
"lastModified": "2023-11-12T01:41:30.154Z",
66
"type": "object",
77
"title": "Front Matter - placeholder",
88
"properties": {

public/config/content.snippets.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "http://json-schema.org/draft-07/schema",
33
"$id": "https://beta.frontmatter.codes/config/content.snippets.schema.json",
44
"description": "Defines the settings for Front Matter snippet",
5-
"lastModified": "2023-10-24T09:28:57.206Z",
5+
"lastModified": "2023-11-12T01:41:30.154Z",
66
"type": "object",
77
"title": "Front Matter - snippet",
88
"required": [

public/config/custom.scripts.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "http://json-schema.org/draft-07/schema",
33
"$id": "https://beta.frontmatter.codes/config/custom.scripts.schema.json",
44
"description": "Defines the settings for Front Matter custom script",
5-
"lastModified": "2023-10-24T09:28:57.205Z",
5+
"lastModified": "2023-11-12T01:41:30.154Z",
66
"type": "object",
77
"title": "Front Matter - custom script",
88
"properties": {

public/config/data.files.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "http://json-schema.org/draft-07/schema",
33
"$id": "https://beta.frontmatter.codes/config/data.files.schema.json",
44
"description": "Defines the settings for Front Matter data file",
5-
"lastModified": "2023-10-24T09:28:57.206Z",
5+
"lastModified": "2023-11-12T01:41:30.154Z",
66
"type": "object",
77
"title": "Front Matter - data file",
88
"properties": {

0 commit comments

Comments
 (0)