File tree Expand file tree Collapse file tree 6 files changed +35
-10
lines changed Expand file tree Collapse file tree 6 files changed +35
-10
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ export function App() {
2121 const switchContent = useCallback ( ( item ) => {
2222 setLoading ( true ) ;
2323 setContent ( null ) ;
24- getContent ( item . url , ( content ) => {
24+ getContent ( item , ( content ) => {
2525 setEditUrl ( remoteUrl ( item . path ) ) ;
2626 setContent ( content ) ;
2727 setLoading ( false ) ;
Original file line number Diff line number Diff line change @@ -30,7 +30,10 @@ export function Content({ content, loading }) {
3030 </ a > ) ;
3131 }
3232
33- return ( < div key = { key } className = { content . type } >
33+ return ( < div key = { key } className = { [
34+ content . type ,
35+ `depth-${ content . depth } ` ,
36+ ] . join ( " " ) } >
3437 { decoded . map ( ( item ) => item ) }
3538 </ div > ) ;
3639 }
Original file line number Diff line number Diff line change 4747 flex-direction : column;
4848 gap : 1rem ;
4949 font-size : 1rem ;
50+ font-weight : 200 ;
51+ line-height : 1.5 ;
5052}
5153
52- .content .heading {
54+ .content .heading . depth-1 {
5355 font-size : 2rem ;
5456 margin-top : 2rem ;
5557 font-weight : 600 ;
5658}
5759
60+ .content .heading .depth-2 {
61+ font-size : 1.5rem ;
62+ margin-top : 1.5rem ;
63+ font-weight : 600 ;
64+ }
65+
66+ .content .heading .depth-3 {
67+ font-size : 1.25rem ;
68+ margin-top : 1.25rem ;
69+ font-weight : 600 ;
70+ }
71+
5872.content .heading : first-child {
5973 margin-top : 0 ;
6074}
Original file line number Diff line number Diff line change 1111 color : var (--color-white );
1212 user-select : none;
1313 -webkit-user-select : none;
14+ font-family : inherit;
1415 transition :
1516 transform 0.3s ease-in-out,
1617 filter 0.3s ease-in-out,
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { useCallback } from "react";
22import { unified } from "unified" ;
33import remarkParse from "remark-parse" ;
44
5- import { getTree } from "./github" ;
5+ import { getTree , rawContentUrl } from "./github" ;
66
77export const useApi = ( ) => {
88 const getTopics = useCallback ( async ( ) => {
@@ -17,6 +17,7 @@ export const useApi = () => {
1717 const sectionName = sectionParts . join ( " " ) ;
1818
1919 sections [ item . path ] = {
20+ path : item . path ,
2021 title : sectionName ,
2122 order : sectionOrder ,
2223 items : [ ] ,
@@ -57,11 +58,11 @@ export const useApi = () => {
5758 ) ;
5859 } , [ ] ) ;
5960
60- const getContent = useCallback ( async ( topicUrl , successCallback ) => {
61- const topicResp = await fetch ( topicUrl ) ;
62- const topicData = await topicResp . json ( ) ;
63- const decoded = decodeURIComponent ( escape ( atob ( topicData . content ) ) ) ;
61+ const getContent = useCallback ( async ( section , successCallback ) => {
62+ const contentResp = await fetch ( rawContentUrl ( section . path ) ) ;
63+ const decoded = await contentResp . text ( ) ;
6464 const content = unified ( ) . use ( remarkParse ) . parse ( decoded ) ;
65+ console . log ( content ) ;
6566
6667 await new Promise ( ( resolve ) => {
6768 setTimeout ( resolve , 1000 ) ;
Original file line number Diff line number Diff line change @@ -2,15 +2,17 @@ const orgName = "GraphScript-Labs";
22const repo = "guidebook" ;
33const branch = "main" ;
44const apiUrl = "https://api.github.com" ;
5+ const rawUrl = "raw.githubusercontent.com" ;
56
67const githubUrl = `${ apiUrl } /repos/${ orgName } /${ repo } /branches/${ branch } ` ;
8+ const headers = { }
79
810export const getTree = async ( ) => {
9- const repoDetailResp = await fetch ( githubUrl ) ;
11+ const repoDetailResp = await fetch ( githubUrl , { headers } ) ;
1012 const repoDetail = await repoDetailResp . json ( ) ;
1113
1214 const treeUrl = repoDetail . commit . commit . tree . url ;
13- const treeResp = await fetch ( `${ treeUrl } ?recursive=1` ) ;
15+ const treeResp = await fetch ( `${ treeUrl } ?recursive=1` , { headers } ) ;
1416 const treeData = await treeResp . json ( ) ;
1517
1618 return treeData . tree ;
@@ -20,3 +22,7 @@ export const remoteUrl = (path) => {
2022 return `https://github.com/${ orgName } /${ repo } /blob/${ branch } /${ path } ` ;
2123}
2224
25+ export const rawContentUrl = ( path ) => {
26+ return `https://${ rawUrl } /${ orgName } /${ repo } /refs/heads/${ branch } /${ path } ` ;
27+ }
28+
You can’t perform that action at this time.
0 commit comments