-
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.
Merge pull request #2 from bluenex/move-static-data
move static data
- Loading branch information
Showing
20 changed files
with
4,947 additions
and
10,655 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 |
---|---|---|
@@ -1 +1 @@ | ||
16 | ||
18 |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { readFileSync } from "fs"; | ||
import { glob } from "glob"; | ||
import matter from "gray-matter"; | ||
import path from "path"; | ||
|
||
const postsDirectory = path.join(process.cwd(), "posts"); | ||
|
||
export function getAllTagsAndYears() { | ||
const fileNames = glob.sync(`${postsDirectory}/**/*.md`); | ||
const yearsSet = new Set<string>(); | ||
const tagsSet = new Set<string>(); | ||
|
||
fileNames.forEach((fileName) => { | ||
const [id] = fileName.split("/").slice(-1); | ||
const [year] = id.split("-"); | ||
|
||
// add year | ||
yearsSet.add(year); | ||
|
||
const filePath = path.join(postsDirectory, id); | ||
const fileContents = readFileSync(filePath, "utf8"); | ||
|
||
const matterResult = matter(fileContents); | ||
|
||
matterResult.data.tags.forEach((tag: string) => { | ||
// add tag | ||
tagsSet.add(tag); | ||
}); | ||
}); | ||
|
||
return { | ||
years: Array.from(yearsSet).sort((a, b) => Number(b) - Number(a)), | ||
tags: Array.from(tagsSet).sort(), | ||
}; | ||
} |
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
Oops, something went wrong.