forked from nickmackenzie/dont-get-zohod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated folder/files names to match convention
- Loading branch information
Showing
16 changed files
with
93 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { Cards, Card } from "nextra/components"; | ||
import { useEffect, useState } from "react"; | ||
|
||
export const RawDocuments = async (folder) => { | ||
return await fetch(`https://api.github.com/repos/nickmackenzie/dont-get-zohod/contents/pages/${folder}`) | ||
.then(response => response.json()) | ||
.catch(error => { | ||
console.error('Error fetching file list:', error); | ||
}); | ||
} | ||
|
||
export const DocumentCards = (props) => { | ||
const [documents, setDocuments] = useState<any[]>([]) | ||
|
||
useEffect(() => { | ||
const func = async () => { | ||
const docList = [] | ||
const documents = await RawDocuments(props.folder) | ||
for (const document of documents.filter(doc => doc.name.includes(".md"))) { | ||
const metadata = await FetchContent(document.git_url); | ||
docList.push({ ...document, ...metadata }) | ||
} | ||
setDocuments(docList); | ||
} | ||
func() | ||
}, []) | ||
|
||
const cards = documents?.sort((a, b) => { | ||
let ta = a.title.toLowerCase(), tb = b.title.toLowerCase(); | ||
//if {ta} is first else if {tb} is fist else 0 | ||
return ta < tb ? -1 : ta > tb ? 1 : 0 | ||
}).map((doc, index) => ( | ||
<Card | ||
key={index} | ||
title={doc.title} | ||
href={doc.path.replace(/(pages\/)/, '').replace(/.[^\/\.]+$/, '')} | ||
/> | ||
)) | ||
|
||
return ( | ||
<Cards> | ||
{cards} | ||
</Cards> | ||
) | ||
} | ||
|
||
const FetchContent = async (url) => { | ||
return await fetch(url) | ||
.then(response => response.json()) | ||
.then(data => extractMetadataFromMarkdown(Buffer.from(data.content, 'base64').toString())) | ||
.catch(error => { | ||
console.error('Error fetching file list:', error); | ||
}); | ||
} | ||
|
||
const extractMetadataFromMarkdown = (markdown) => { | ||
const charactersBetweenGroupedHyphens = /^---([\s\S]*?)---/; | ||
const metadataMatched = markdown.match(charactersBetweenGroupedHyphens); | ||
const metadata = metadataMatched[1]; | ||
|
||
if (!metadata) { | ||
return {}; | ||
} | ||
|
||
const metadataLines = metadata.split("\n"); | ||
const metadataObject = metadataLines.reduce((accumulator, line) => { | ||
const [key, ...value] = line.split(":").map((part) => part.trim()); | ||
|
||
if (key) | ||
accumulator[key] = value[1] ? value.join(":") : value.join(""); | ||
return accumulator; | ||
}, {}); | ||
|
||
return metadataObject; | ||
}; |
2 changes: 1 addition & 1 deletion
2
components/zoho-icons/index.jsx → components/zohoIcons/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
components/zoho-icons/zoho-icons.module.css → components/zohoIcons/zohoIcons.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"TimeDates":"Time & Dates" | ||
} | ||
{ | ||
"buttons": "Buttons", | ||
"lists": "Lists", | ||
"strings": "Strings", | ||
"timeDates": "Time & Dates" | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters