generated from idea2app/Next-Bootstrap-ts
-
Notifications
You must be signed in to change notification settings - Fork 6
[add] Recipe Wiki pages for CookLikeHOC repository with code refactoring #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TechQuery
merged 4 commits into
main
from
copilot/fix-ea07d89d-d4f4-45f2-87ca-9127e5f17913
Sep 22, 2025
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2e5ce52
Initial plan
Copilot 0195cb0
Add complete recipes section for CookLikeHOC repository
Copilot 35e585b
Address code review feedback: add navigation link, acknowledgment, sh…
Copilot a1057c2
[optimize] simplify JSX structure & Data filter of GitHub-based Markd…
TechQuery File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,152 @@ | ||
import { marked } from 'marked'; | ||
import { observer } from 'mobx-react'; | ||
import { GetStaticPaths, GetStaticProps } from 'next'; | ||
import { ParsedUrlQuery } from 'querystring'; | ||
import { FC, useContext } from 'react'; | ||
import { Badge, Breadcrumb, Button, Container } from 'react-bootstrap'; | ||
import { decodeBase64 } from 'web-utility'; | ||
|
||
import { PageHead } from '../../components/Layout/PageHead'; | ||
import { I18nContext } from '../../models/Translation'; | ||
import { recipeContentStore, XContent } from '../../models/Wiki'; | ||
import { splitFrontMatter } from '../api/core'; | ||
|
||
interface RecipePageParams extends ParsedUrlQuery { | ||
slug: string[]; | ||
} | ||
|
||
export const getStaticPaths: GetStaticPaths<RecipePageParams> = async () => { | ||
const nodes = await recipeContentStore.getAll(); | ||
|
||
const paths = nodes | ||
.filter(({ type }) => type === 'file') | ||
.map(({ path }) => ({ params: { slug: path.split('/') } })); | ||
|
||
return { paths, fallback: 'blocking' }; | ||
}; | ||
|
||
export const getStaticProps: GetStaticProps<XContent, RecipePageParams> = async ({ params }) => { | ||
const { slug } = params!; | ||
|
||
const node = await recipeContentStore.getOne(slug.join('/')); | ||
|
||
const { meta, markdown } = splitFrontMatter(decodeBase64(node.content!)); | ||
|
||
const markup = marked(markdown) as string; | ||
|
||
return { | ||
props: JSON.parse(JSON.stringify({ ...node, content: markup, meta })), | ||
revalidate: 300, // Revalidate every 5 minutes | ||
}; | ||
}; | ||
|
||
const RecipePage: FC<XContent> = observer(({ name, path, parent_path, content, meta }) => { | ||
const { t } = useContext(I18nContext); | ||
|
||
return ( | ||
<Container className="py-4"> | ||
<PageHead title={name} /> | ||
|
||
<Breadcrumb className="mb-4"> | ||
<Breadcrumb.Item href="/recipes">{t('recipes')}</Breadcrumb.Item> | ||
|
||
{parent_path?.split('/').map((segment, index, array) => { | ||
const breadcrumbPath = array.slice(0, index + 1).join('/'); | ||
|
||
return ( | ||
<Breadcrumb.Item key={breadcrumbPath} href={`/recipes/${breadcrumbPath}`}> | ||
{segment} | ||
</Breadcrumb.Item> | ||
); | ||
})} | ||
<Breadcrumb.Item active>{name}</Breadcrumb.Item> | ||
</Breadcrumb> | ||
|
||
<article> | ||
<header className="mb-4"> | ||
<h1>{name}</h1> | ||
|
||
{meta && ( | ||
<div className="d-flex flex-wrap align-items-center gap-3 mb-3"> | ||
<ul className="mb-0"> | ||
{meta['category'] && ( | ||
<li> | ||
<Badge bg="primary">{meta['category']}</Badge> | ||
</li> | ||
)} | ||
{meta['difficulty'] && ( | ||
<li> | ||
<Badge bg="secondary">{meta['difficulty']}</Badge> | ||
</li> | ||
)} | ||
{meta['time'] && ( | ||
<li> | ||
<Badge bg="success">{meta['time']}</Badge> | ||
</li> | ||
)} | ||
</ul> | ||
</div> | ||
)} | ||
|
||
<div className="d-flex justify-content-between align-items-center text-muted small mb-3"> | ||
<div> | ||
{meta?.['servings'] && ( | ||
<span> | ||
{t('servings')}: {meta['servings']} | ||
</span> | ||
)} | ||
{meta?.['prep_time'] && ( | ||
<span className="ms-3"> | ||
{t('prep_time')}: {meta['prep_time']} | ||
</span> | ||
)} | ||
</div> | ||
|
||
<div className="d-flex gap-2"> | ||
<Button | ||
variant="outline-primary" | ||
size="sm" | ||
href={`https://github.com/Gar-b-age/CookLikeHOC/blob/main/${path}`} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
{t('edit_on_github')} | ||
</Button> | ||
{meta?.url && ( | ||
<Button | ||
variant="outline-secondary" | ||
size="sm" | ||
href={meta.url} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
{t('view_original')} | ||
</Button> | ||
)} | ||
</div> | ||
</div> | ||
</header> | ||
|
||
<div dangerouslySetInnerHTML={{ __html: content || '' }} className="markdown-body" /> | ||
</article> | ||
|
||
<footer className="mt-5 pt-4 border-top"> | ||
<div className="text-center"> | ||
<p className="text-muted"> | ||
{t('github_recipe_description')} | ||
<a | ||
href={`https://github.com/Gar-b-age/CookLikeHOC/blob/main/${path}`} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
className="ms-2" | ||
> | ||
{t('view_or_edit_on_github')} | ||
</a> | ||
</p> | ||
</div> | ||
</footer> | ||
</Container> | ||
); | ||
}); | ||
|
||
export default RecipePage; |
This file contains hidden or 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,89 @@ | ||
import { observer } from 'mobx-react'; | ||
import { GetStaticProps } from 'next'; | ||
import Link from 'next/link'; | ||
import React, { FC, useContext } from 'react'; | ||
import { Badge, Button, Card, Container } from 'react-bootstrap'; | ||
import { treeFrom } from 'web-utility'; | ||
|
||
import { PageHead } from '../../components/Layout/PageHead'; | ||
import { I18nContext } from '../../models/Translation'; | ||
import { recipeContentStore, XContent } from '../../models/Wiki'; | ||
import { MD_pattern, splitFrontMatter } from '../api/core'; | ||
|
||
export const getStaticProps: GetStaticProps<{ nodes: XContent[] }> = async () => { | ||
const nodes = (await recipeContentStore.getAll()) | ||
.filter(({ type, name }) => type !== 'file' || MD_pattern.test(name)) | ||
.map(({ content, ...rest }) => { | ||
const { meta, markdown } = content ? splitFrontMatter(content) : {}; | ||
|
||
return { ...rest, content: markdown, meta }; | ||
}); | ||
|
||
return { | ||
props: JSON.parse(JSON.stringify({ nodes })), | ||
revalidate: 300, // Revalidate every 5 minutes | ||
}; | ||
}; | ||
|
||
const renderTree = (nodes: XContent[], level = 0) => ( | ||
<ol className={level === 0 ? 'list-unstyled' : ''}> | ||
{nodes.map(({ path, name, type, meta, children }) => ( | ||
<li key={path} className={level > 0 ? 'ms-3' : ''}> | ||
{type !== 'dir' ? ( | ||
<Link className="h4 d-flex align-items-center py-1" href={`/recipes/${path}`}> | ||
{name} | ||
|
||
{meta?.['category'] && ( | ||
<Badge bg="secondary" className="ms-2 small"> | ||
{meta['category']} | ||
</Badge> | ||
)} | ||
</Link> | ||
) : ( | ||
<details> | ||
<summary className="h4">{name}</summary> | ||
|
||
{renderTree(children || [], level + 1)} | ||
</details> | ||
)} | ||
</li> | ||
))} | ||
</ol> | ||
); | ||
TechQuery marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
const RecipeIndexPage: FC<{ nodes: XContent[] }> = observer(({ nodes }) => { | ||
const { t } = useContext(I18nContext); | ||
|
||
return ( | ||
<Container className="py-4"> | ||
<PageHead title={`${t('recipes')} - ${t('knowledge_base')}`} /> | ||
|
||
<hgroup className="d-flex justify-content-between align-items-center mb-4"> | ||
<h1> | ||
{t('recipes')} ({nodes.length}) | ||
</h1> | ||
<Button | ||
href="https://github.com/Gar-b-age/CookLikeHOC" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
variant="outline-primary" | ||
> | ||
{t('contribute_content')} | ||
</Button> | ||
</hgroup> | ||
|
||
{nodes[0] ? ( | ||
renderTree(treeFrom(nodes, 'path', 'parent_path', 'children')) | ||
) : ( | ||
<Card> | ||
<Card.Body className="text-muted text-center"> | ||
<p>{t('no_docs_available')}</p> | ||
<p>{t('docs_auto_load_from_github')}</p> | ||
</Card.Body> | ||
</Card> | ||
)} | ||
</Container> | ||
); | ||
}); | ||
|
||
export default RecipeIndexPage; |
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.