Skip to content

Commit 4f3fa0f

Browse files
committed
feat: update blog content and enhance markdown styling
1 parent 61d3f44 commit 4f3fa0f

File tree

7 files changed

+57
-174
lines changed

7 files changed

+57
-174
lines changed

.astro/content-modules.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11

22
export default new Map([
3+
["src/content/blog/code-tabs.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Fblog%2Fcode-tabs.mdx&astroContentModuleFlag=true")],
4+
["src/content/blog/welcome.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Fblog%2Fwelcome.mdx&astroContentModuleFlag=true")],
35
["src/content/docs/framework/blog.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Fdocs%2Fframework%2Fblog.mdx&astroContentModuleFlag=true")],
4-
["src/content/docs/framework/docs.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Fdocs%2Fframework%2Fdocs.mdx&astroContentModuleFlag=true")],
56
["src/content/docs/framework/configuration.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Fdocs%2Fframework%2Fconfiguration.mdx&astroContentModuleFlag=true")],
7+
["src/content/docs/framework/docs.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Fdocs%2Fframework%2Fdocs.mdx&astroContentModuleFlag=true")],
68
["src/content/docs/framework/getting-started.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Fdocs%2Fframework%2Fgetting-started.mdx&astroContentModuleFlag=true")],
7-
["src/content/docs/framework/installation.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Fdocs%2Fframework%2Finstallation.mdx&astroContentModuleFlag=true")],
89
["src/content/docs/framework/project-structure.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Fdocs%2Fframework%2Fproject-structure.mdx&astroContentModuleFlag=true")],
9-
["src/content/blog/code-tabs.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Fblog%2Fcode-tabs.mdx&astroContentModuleFlag=true")],
10-
["src/content/docs/syntax/code-block.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Fdocs%2Fsyntax%2Fcode-block.mdx&astroContentModuleFlag=true")],
11-
["src/content/blog/welcome.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Fblog%2Fwelcome.mdx&astroContentModuleFlag=true")],
10+
["src/content/docs/framework/installation.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Fdocs%2Fframework%2Finstallation.mdx&astroContentModuleFlag=true")],
1211
["src/content/docs/syntax/alert.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Fdocs%2Fsyntax%2Falert.mdx&astroContentModuleFlag=true")],
13-
["src/content/docs/syntax/text.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Fdocs%2Fsyntax%2Ftext.mdx&astroContentModuleFlag=true")],
14-
["src/content/docs/syntax/markdown.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Fdocs%2Fsyntax%2Fmarkdown.mdx&astroContentModuleFlag=true")]]);
12+
["src/content/docs/syntax/code-block.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Fdocs%2Fsyntax%2Fcode-block.mdx&astroContentModuleFlag=true")],
13+
["src/content/docs/syntax/markdown.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Fdocs%2Fsyntax%2Fmarkdown.mdx&astroContentModuleFlag=true")],
14+
["src/content/docs/syntax/text.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Fdocs%2Fsyntax%2Ftext.mdx&astroContentModuleFlag=true")]]);
1515

.astro/data-store.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/assets/css/markdown.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,14 @@ html.dark .prose>.astro-code {
313313
border-radius: 0.5rem;
314314
}
315315

316+
.prose p {
317+
padding-top: 0.5rem;
318+
padding-bottom: 0.5rem;
319+
text-align: justify;
320+
hyphens: auto;
321+
}
322+
323+
316324
.astro-code code {
317325
display: flex;
318326
flex-direction: column;

src/content/blog/code-tabs.mdx

Lines changed: 0 additions & 96 deletions
This file was deleted.

src/content/blog/welcome.mdx

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,15 @@ authors:
88
publishedAt: 2024-01-01:23:00:00
99
---
1010

11-
:read-more{to="/docs/guide/directory-structure/pages/#page-metadata"}
11+
# Welcome to Explainer
1212

13-
:::code-group labels=[pnpm,,app.dart]
14-
```bash
15-
npm install rehype-code-group
16-
```
13+
Explainer is a documentation boilerplate designed to help you create beautiful, responsive, and accessible web documentation using [Astro](https://astro.build). This project combines the power of Astro with [Tailwind CSS](https://tailwindcss.com) and [TypeScript](https://www.typescriptlang.org) to provide a smooth development experience.
1714

18-
```rs
19-
pub struct Foo {
20-
pub name: String,
21-
}
15+
## Why Explainer?
2216

23-
impl Foo {
24-
pub fn new(name: String) -> Self {
25-
Self { name }
26-
}
27-
}
28-
```
29-
:::
17+
Documentation is often overlooked, but it's essential for the adoption and effective use of your project.
18+
Explainer fills an important gap in the technical documentation ecosystem. While Vue has robust solutions like Vitepress, the React ecosystem suffers from a lack of alternatives that don't depend on Next.js. Most documentation frameworks for React are closely tied to Next.js, which can be limiting for many projects.
3019

31-
:read-more{to="/docs/guide/directory-structure/pages/#page-metadata"}
20+
This is where Astro, and by extension Explainer, particularly shines. Astro offers remarkable flexibility by allowing you to integrate any technological component related to your business. You can easily incorporate React, Vue, Svelte components, or even standard web elements according to your specific needs.
3221

33-
:::code-group labels=[pnpm,app.dart]
34-
```bash
35-
npm install rehype-code-group
36-
```
37-
38-
```rs
39-
pub struct Foo {
40-
pub name: String,
41-
}
42-
43-
impl Foo {
44-
pub fn new(name: String) -> Self {
45-
Self { name }
46-
}
47-
}
48-
```
49-
:::
22+
This agnostic approach allows you to create documentation that perfectly aligns with your existing technology stack, without forcing you to adopt a particular ecosystem. Whether you work with React, Vue, or other frameworks, Explainer adapts to your needs rather than the other way around.

src/lib/plugins/code-group/plugin.ts

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const rehypeCodeGroupReact: Plugin<[], Root> = () => {
99
parent: any;
1010
index: number;
1111
endIndex: number;
12-
labels: string[];
12+
labels: string[] | null;
13+
languages: string[]
1314
}[] = [];
1415

1516
// First pass: identify code groups
@@ -22,15 +23,24 @@ const rehypeCodeGroupReact: Plugin<[], Root> = () => {
2223
node.children[0].type === 'text'
2324
) {
2425
const textContent = node.children[0].value;
25-
const match = textContent.match(/^:::code-group\s+labels=\[(.*?)\]$/);
2626

27-
if (match && parent && typeof index === 'number') {
28-
// Found a code-group start, now find the end
29-
const labels = match[1].split(',').map(label => label.trim());
27+
const matchWithoutLabels = textContent.match(/^:::code-group auto$/);
28+
const matchWithLabels = textContent.match(/^:::code-group\s+labels=\[(.*?)\]$/);
3029

30+
if ((matchWithLabels || matchWithoutLabels) && parent && typeof index === 'number') {
3131
let endIndex = -1;
32+
33+
let labels = []
34+
let languages: string[] = []
3235
for (let i = index + 1; i < parent.children.length; i++) {
33-
const child = parent.children[i];
36+
const child = parent.children[i]
37+
38+
if (child.type === 'element' && child.tagName === 'pre' &&
39+
'properties' in child && child.properties?.dataLanguage) {
40+
labels.push(child.properties!.dataLanguage as string)
41+
languages.push(child.properties!.dataLanguage as string)
42+
}
43+
3444
if (
3545
child.type === 'element' &&
3646
child.tagName === 'p' &&
@@ -45,74 +55,62 @@ const rehypeCodeGroupReact: Plugin<[], Root> = () => {
4555
}
4656

4757
if (endIndex !== -1) {
58+
if (matchWithLabels) {
59+
matchWithLabels[1].split(',').forEach((label, index) => {
60+
if (label.length) {
61+
labels[index] = label.trim()
62+
}
63+
})
64+
}
65+
4866
codeGroups.push({
4967
parent,
5068
index,
5169
endIndex,
52-
labels
70+
labels,
71+
languages
5372
});
5473
}
5574
}
5675
}
5776
});
5877

59-
// Second pass: process code groups
6078
for (let i = codeGroups.length - 1; i >= 0; i--) {
61-
const { parent, index, endIndex, labels } = codeGroups[i];
79+
const { parent, index, endIndex, labels: providedLabels, languages: providedLanguages } = codeGroups[i];
6280

63-
// Extract code blocks
6481
const codeBlocks = parent.children.slice(index + 1, endIndex)
6582
.filter((node: any) => node.type === 'element' && node.tagName === 'pre');
6683

67-
const languages: string[] = [];
6884
const codes: string[] = [];
85+
const extractedLabels: string[] = [];
6986

7087
codeBlocks.forEach((codeBlock: Element) => {
7188
const codeElement = codeBlock.children[0] as Element;
7289

7390
if (codeElement && codeElement.type === 'element' && codeElement.tagName === 'code') {
74-
// Get language from class (e.g., "language-js" -> "js")
75-
const className = codeElement.properties?.className as string[] || [];
76-
const langClass = className.find(cls => cls.startsWith('language-'));
77-
const language = langClass ? langClass.replace('language-', '') : '';
78-
79-
languages.push(language);
80-
81-
// Preserve the entire HTML output from Shiki including syntax highlighting
8291
const codeHtml = toHtml(codeBlock);
8392
codes.push(codeHtml);
8493
}
8594
});
8695

87-
// Create the MDX JSX element
88-
if (languages.length > 0 && codes.length > 0) {
96+
const finalLabels = providedLabels || extractedLabels;
97+
if (providedLanguages.length > 0 && codes.length > 0) {
8998
const newNode = {
9099
type: 'mdxJsxFlowElement',
91100
name: 'CodeGroupWrapper',
92101
attributes: [
93-
{ type: 'mdxJsxAttribute', name: 'labels', value: JSON.stringify(labels) },
94-
{ type: 'mdxJsxAttribute', name: 'languages', value: JSON.stringify(languages) },
102+
{ type: 'mdxJsxAttribute', name: 'labels', value: JSON.stringify(finalLabels) },
103+
{ type: 'mdxJsxAttribute', name: 'languages', value: JSON.stringify(providedLanguages) },
95104
{ type: 'mdxJsxAttribute', name: 'codes', value: JSON.stringify(codes) }
96105
],
97106
children: [],
98107
data: { _mdxExplicitJsx: true }
99108
};
100109

101-
// Replace all nodes from start to end with the new component
102110
parent.children.splice(index, endIndex - index + 1, newNode);
103111
}
104112
}
105113
};
106114
};
107115

108-
// Helper function to get text content from a node
109-
function getTextContent(node: any): string {
110-
if (node.type === 'text') {
111-
return node.value;
112-
} else if (node.children) {
113-
return node.children.map(getTextContent).join('');
114-
}
115-
return '';
116-
}
117-
118116
export default rehypeCodeGroupReact;

src/pages/blog/[slug].astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ const headingTree = buildHeadingTree(availableHeadings);
166166
</div>
167167
</div>
168168

169-
<div class="flex gap-10 w-full">
170-
<div class="w-full">
169+
<div class="flex justify-between gap-10 w-full">
170+
<div class="w-full max-w-4xl">
171171
<div class="prose">
172172
<Content components={{ CodeGroupWrapper, ReadMoreWrapper }} />
173173
</div>

0 commit comments

Comments
 (0)