-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
35 additions
and
41 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
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 |
---|---|---|
@@ -1,29 +1,19 @@ | ||
import { Author, getAllAuthors } from "./author"; | ||
import { BlogPost, compareBlogPostsByDate } from "./post"; | ||
import { getAllAuthors as getAllAuthorsFromFile } from "./author"; | ||
import { compareBlogPostsByDate } from "./post"; | ||
import { getAllPosts } from "./post-loading"; | ||
import { join, resolve } from "path"; | ||
import { cache } from "react"; | ||
|
||
export interface SiteData { | ||
posts: readonly BlogPost[]; | ||
pressReleases: readonly BlogPost[]; | ||
authors: readonly Author[]; | ||
} | ||
const contentRoot = resolve(process.cwd(), "content"); | ||
|
||
function loadSiteData(): SiteData { | ||
const content = resolve(process.cwd(), "content"); | ||
console.log(`Loading data files from ${content}`); | ||
const byDate = compareBlogPostsByDate; | ||
const posts = getAllPosts(join(content, "posts")).sort(byDate); | ||
const pressReleases = getAllPosts(join(content, "press")).sort(byDate); | ||
const authors = getAllAuthors(join(content, "authors.yaml")); | ||
console.log( | ||
`Loaded ${posts.length} posts, ${pressReleases.length} press releases, ${authors.length} authors.` | ||
); | ||
return { | ||
posts, | ||
pressReleases, | ||
authors, | ||
}; | ||
} | ||
export const getAllBlogPosts = cache(() => | ||
getAllPosts(join(contentRoot, "posts")).sort(compareBlogPostsByDate) | ||
); | ||
|
||
export const siteData = loadSiteData(); | ||
export const getAllPressReleases = cache(() => | ||
getAllPosts(join(contentRoot, "press")).sort(compareBlogPostsByDate) | ||
); | ||
|
||
export const getAllAuthors = cache(() => | ||
getAllAuthorsFromFile(join(contentRoot, "authors.yaml")) | ||
); |