Skip to content

Commit 076028b

Browse files
committed
Update APIs and Fonts
1 parent 128afb3 commit 076028b

File tree

6 files changed

+35
-10
lines changed

6 files changed

+35
-10
lines changed

src/App.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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);

src/components/Content/index.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

src/components/Content/style.css

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,28 @@
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
}

src/styles/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
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,

src/utils/api.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useCallback } from "react";
22
import { unified } from "unified";
33
import remarkParse from "remark-parse";
44

5-
import { getTree } from "./github";
5+
import { getTree, rawContentUrl } from "./github";
66

77
export 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);

src/utils/github.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ const orgName = "GraphScript-Labs";
22
const repo = "guidebook";
33
const branch = "main";
44
const apiUrl = "https://api.github.com";
5+
const rawUrl = "raw.githubusercontent.com";
56

67
const githubUrl = `${apiUrl}/repos/${orgName}/${repo}/branches/${branch}`;
8+
const headers = {}
79

810
export 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+

0 commit comments

Comments
 (0)