-
Notifications
You must be signed in to change notification settings - Fork 11
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 #239 from ocftw/fix/adjust-navigation-bar-and-font…
…-size-in-layout
- Loading branch information
Showing
6 changed files
with
64 additions
and
100 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import fs from 'fs'; | ||
import { join } from 'path'; | ||
import matter from 'gray-matter'; | ||
|
||
const pagesDirectory = join(process.cwd(), '_pages'); | ||
|
||
function getPagesDirectoryPath(lang) { | ||
return join(pagesDirectory, lang); | ||
} | ||
|
||
export async function getPagesList(lang) { | ||
const pagesDirectory = getPagesDirectoryPath(lang); | ||
const filesInPages = fs.readdirSync(pagesDirectory); | ||
|
||
const pagesList = filesInPages.map(async (filename) => { | ||
const fullPath = join(pagesDirectory, filename); | ||
const file = fs.readFileSync(fullPath, 'utf8'); | ||
const matterFile = matter(file); | ||
const { data, content } = matterFile; | ||
|
||
return { | ||
path: data.unique_slug, | ||
name: data.name, | ||
}; | ||
}); | ||
|
||
return Promise.all(pagesList); | ||
} | ||
|
||
export async function getNavigationList(lang) { | ||
const pagesList = await getPagesList(lang); | ||
const cardsPage = { | ||
en: 'Cards', | ||
'zh-tw': '卡片頁', | ||
}; | ||
|
||
// * dynamic page navigation | ||
const navigationList = pagesList | ||
.filter((page) => page.path && page.name) | ||
.map((page) => { | ||
page.path = page.path.replace('index', ''); | ||
return { link: `/${page.path}`, text: page.name }; | ||
}); | ||
// add hard coded cards page | ||
navigationList.push({ link: `/cards`, text: cardsPage[lang] }); | ||
|
||
return navigationList; | ||
} |
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