@@ -14,6 +14,20 @@ const giscusThemeList = [
1414 "catppuccin_latte", "catppuccin_frappe", "catppuccin_macchiato", "catppuccin_mocha", "fro"
1515];
1616
17+
18+ // comment manager -
19+
20+ const comments = new CommentManager({
21+ repo: "YOUR_NAME/YOUR_REPO",
22+ repoId: "YOUR_REPO_ID",
23+ category: "General",
24+ categoryId: "YOUR_CATEGORY_ID",
25+ containerId: "comments",
26+ });
27+
28+ comments.load(post.slug);
29+ comments.unload();
30+
1731*/
1832
1933
@@ -26,7 +40,7 @@ export class CommentManager {
2640 containerId = "comments" ,
2741 theme = "cobalt" ,
2842 lang = "en" ,
29- } ) {
43+ } ) {
3044 this . booted = false ;
3145 this . repo = repo ;
3246 this . repoId = repoId ;
@@ -35,54 +49,35 @@ export class CommentManager {
3549 this . containerId = containerId ;
3650 this . theme = theme ;
3751 this . lang = lang ;
52+ this . script = null ;
3853
3954 this . handleMessage = this . handleMessage . bind ( this ) ;
4055 window . addEventListener ( "message" , this . handleMessage ) ;
4156 }
4257
43- handleMessage ( event ) {
44- if ( event . origin !== "https://giscus.app" ) return ;
45- if ( ! ( event . data && typeof event . data === "object" && event . data . giscus ) ) return ;
58+ handleMessage ( event ) {
59+ if ( event . origin !== "https://giscus.app" ) return ;
60+ if ( ! ( event . data && typeof event . data === "object" && event . data . giscus ) ) return ;
4661
4762 const giscus = event . data . giscus ;
48- if ( giscus . resizeHeight ) {
63+ if ( giscus . resizeHeight ) {
4964 const container = document . getElementById ( this . containerId ) ;
50- if ( container ) {
65+ if ( container ) {
5166 container . style . height = `${ giscus . resizeHeight + 30 } px` ;
5267 }
5368 }
5469 }
5570
56- load ( postId ) {
57-
71+ load ( postId ) {
5872 const container = document . getElementById ( this . containerId ) ;
59- if ( ! container ) {
73+ if ( ! container ) {
6074 console . warn ( "[CommentManager] Container not found:" , this . containerId ) ;
6175 return ;
6276 }
6377
6478 this . booted = true ;
6579 container . innerHTML = "" ;
6680
67- /* Generated from Giscus.app --
68- <script src="https://giscus.app/client.js"
69- data-repo="ProcStack/procDiscussions"
70- data-repo-id="R_kgDORc_LJw"
71- data-category="General"
72- data-category-id="DIC_kwDORc_LJ84C3kiH"
73- data-mapping="pathname"
74- data-strict="0"
75- data-reactions-enabled="1"
76- data-emit-metadata="0"
77- data-input-position="top"
78- data-theme="cobalt"
79- data-lang="en"
80- data-loading="lazy"
81- crossorigin="anonymous"
82- async>
83- </script>
84- */
85-
8681 const script = document . createElement ( "script" ) ;
8782 script . src = "https://giscus.app/client.js" ;
8883 script . async = true ;
@@ -99,30 +94,37 @@ export class CommentManager {
9994 script . dataset . strict = "0" ;
10095
10196 script . dataset . reactionsEnabled = "1" ;
102- script . dataset . emitMetadata = "1 " ;
97+ script . dataset . emitMetadata = "0 " ;
10398 script . dataset . inputPosition = "top" ;
10499 script . dataset . theme = this . theme ;
105100 script . dataset . lang = this . lang ;
106101 script . dataset . loading = "lazy" ;
107102
108-
109-
110- container . appendChild ( script ) ;
103+ // Add and store script reference
104+ container . appendChild ( script ) ;
105+ this . script = script ;
111106 }
112107
113- unload ( ) {
108+ unload ( ) {
114109 const container = document . getElementById ( this . containerId ) ;
115- if ( ! container ) return ;
110+ if ( ! container ) return ;
116111
117112 container . innerHTML = "" ;
118113 this . booted = false ;
114+
115+ // Clean up for easier pre-rendered procPages
116+ // Repo - ./packing/renderPages.jsx
117+ if ( this . script ) {
118+ this . script . remove ( ) ;
119+ this . script = null ;
120+ }
119121 }
120122
121- setTheme ( theme ) {
123+ setTheme ( theme ) {
122124 this . theme = theme ;
123125
124126 const iframe = document . querySelector ( "iframe.giscus-frame" ) ;
125- if ( ! iframe ) return ;
127+ if ( ! iframe ) return ;
126128
127129 iframe . contentWindow . postMessage (
128130 {
@@ -134,7 +136,7 @@ export class CommentManager {
134136 ) ;
135137 }
136138
137- isBooted ( ) {
139+ isBooted ( ) {
138140 return this . booted ;
139141 }
140142}
0 commit comments