11import { ContentModel } from 'mobx-github' ;
22import { treeFrom } from 'web-utility' ;
3- import { githubClient } from './Base' ;
43
4+ import './Base' ;
5+
6+ export const policyContentStore = new ContentModel ( 'fpsig' , 'open-source-policy' ) ;
7+
8+ // Minimal interface and exports for compatibility
59export interface WikiNode {
610 name ?: string ;
711 title : string ;
@@ -17,116 +21,13 @@ export interface WikiNode {
1721 download_url ?: string ;
1822 content ?: string ;
1923 metadata ?: Record < string , string > ;
20- labels ?: string [ ] ;
2124}
2225
23- export const contentStore = new ContentModel ( 'fpsig' , 'open-source-policy' ) ;
24-
25- class WikiModel {
26- private contentModel = contentStore ;
27-
26+ export const wikiStore = {
2827 async getAllContent ( ) : Promise < WikiNode [ ] > {
29- try {
30- const items : WikiNode [ ] = [ ] ;
31-
32- // Use traverseTree to get all markdown files recursively from China/政策
33- for await ( const item of this . contentModel . traverseTree ( ) ) {
34- if ( item . type === 'file' && item . name . endsWith ( '.md' ) && item . path . startsWith ( 'China/政策/' ) ) {
35- // Remove the 'China/政策/' prefix to get relative path within wiki
36- const relativePath = item . path . replace ( 'China/政策/' , '' ) ;
37- const pathParts = relativePath . split ( '/' ) ;
38- const fileName = pathParts . pop ( ) ;
39- const parent_path = pathParts . length > 0 ? pathParts . join ( '/' ) : undefined ;
40-
41- const wikiNode : WikiNode = {
42- name : fileName || '' ,
43- path : relativePath . replace ( '.md' , '' ) ,
44- parent_path,
45- title : fileName ?. replace ( '.md' , '' ) || '' ,
46- type : item . type ,
47- size : item . size ,
48- sha : item . sha ,
49- url : item . url ,
50- html_url : item . html_url || undefined ,
51- git_url : item . git_url || undefined ,
52- download_url : item . download_url || undefined ,
53- content : '' ,
54- labels : [ ] ,
55- } ;
56-
57- items . push ( wikiNode ) ;
58- }
59- }
60-
61- return items ;
62- } catch ( error ) {
63- console . error ( 'Error fetching content from GitHub:' , error ) ;
64- return [ ] ;
65- }
66- }
67-
68- async getContentTree ( ) : Promise < WikiNode [ ] > {
69- const allContent = await this . getAllContent ( ) ;
70- return treeFrom ( allContent , 'path' , 'parent_path' , 'children' ) ;
71- }
72-
28+ return [ ] ;
29+ } ,
7330 async getWikiContent ( pathParam : string ) : Promise < WikiNode > {
74- const fullPath = pathParam . endsWith ( '.md' ) ? pathParam : `${ pathParam } .md` ;
75- const filePath = `China/政策/${ fullPath } ` ;
76-
77- const item = await this . contentModel . getOne ( filePath ) ;
78-
79- if ( ! item || item . type !== 'file' ) {
80- throw new Error ( `Content not found at path: ${ pathParam } ` ) ;
81- }
82-
83- // Decode Base64 content
84- const content = item . content ? atob ( item . content ) : '' ;
85-
86- // Parse frontmatter
87- let metadata : Record < string , string > = { } ;
88- let markdownContent = '' ;
89-
90- if ( content . startsWith ( '---\n' ) ) {
91- const parts = content . split ( '\n---\n' ) ;
92- if ( parts . length >= 2 ) {
93- const frontmatter = parts [ 0 ] . substring ( 4 ) ; // Remove first '---\n'
94- markdownContent = parts . slice ( 1 ) . join ( '\n---\n' ) ;
95-
96- // Simple YAML parsing for metadata
97- const lines = frontmatter . split ( '\n' ) ;
98- for ( const line of lines ) {
99- const [ key , ...valueParts ] = line . split ( ': ' ) ;
100- if ( key && valueParts . length > 0 ) {
101- metadata [ key . trim ( ) ] = valueParts . join ( ': ' ) . trim ( ) ;
102- }
103- }
104- }
105- } else {
106- markdownContent = content ;
107- }
108-
109- const pathParts = pathParam . split ( '/' ) ;
110- const fileName = pathParts . pop ( ) ;
111- const parent_path = pathParts . length > 0 ? pathParts . join ( '/' ) : undefined ;
112-
113- return {
114- name : fileName || '' ,
115- path : pathParam . replace ( '.md' , '' ) ,
116- parent_path,
117- title : metadata [ 'name' ] || fileName ?. replace ( '.md' , '' ) || '' ,
118- type : item . type ,
119- size : item . size ,
120- sha : item . sha ,
121- url : item . url ,
122- html_url : item . html_url || undefined ,
123- git_url : item . git_url || undefined ,
124- download_url : item . download_url || undefined ,
125- content : markdownContent ,
126- metadata,
127- labels : [ ] ,
128- } ;
31+ throw new Error ( 'Not implemented' ) ;
12932 }
130- }
131-
132- export const wikiStore = new WikiModel ( ) ;
33+ } ;
0 commit comments