File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { themes as prismThemes } from "prism-react-renderer";
22import type { Config } from "@docusaurus/types" ;
33import type * as Preset from "@docusaurus/preset-classic" ;
44import * as dotenv from "dotenv" ;
5+ import giscusInjector from "./src/plugins/giscus-injector" ;
56dotenv . config ( ) ;
67
78// This runs in Node.js - Don't use client-side code here (browser APIs, JSX...)
@@ -53,6 +54,7 @@ const config: Config = {
5354 sidebarPath : require . resolve ( "./sidebars.ts" ) ,
5455 editUrl : ( { docPath } ) =>
5556 `https://github.com/recodehive/recode-website/tree/main/docs/${ docPath } ` ,
57+ remarkPlugins : [ giscusInjector ] ,
5658 } ,
5759 blog : {
5860 showReadingTime : true ,
Original file line number Diff line number Diff line change 1+ const { visit } = require ( "unist-util-visit" ) ;
2+
3+ /**
4+ * Remark plugin to automatically inject GiscusComments component
5+ * at the end of MDX files that don't already have it
6+ */
7+ export default function giscusInjector ( ) {
8+ return ( tree ) => {
9+ let hasGiscus = false ;
10+
11+ // Check if GiscusComments already exists
12+ visit ( tree , ( node ) => {
13+ // Check JSX elements
14+ if (
15+ node . type === "mdxJsxFlowElement" ||
16+ node . type === "mdxJsxTextElement"
17+ ) {
18+ if ( node . name === "GiscusComments" ) {
19+ hasGiscus = true ;
20+ }
21+ }
22+
23+ // Check raw JSX strings
24+ if (
25+ node . type === "jsx" &&
26+ node . value &&
27+ node . value . includes ( "GiscusComments" )
28+ ) {
29+ hasGiscus = true ;
30+ }
31+ } ) ;
32+
33+ // Only inject if not present
34+ if ( ! hasGiscus ) {
35+ // Add the component as an MDX JSX element
36+ tree . children . push ( {
37+ type : "mdxJsxFlowElement" ,
38+ name : "GiscusComments" ,
39+ attributes : [ ] ,
40+ children : [ ] ,
41+ } ) ;
42+ }
43+ } ;
44+ }
You can’t perform that action at this time.
0 commit comments