-
Notifications
You must be signed in to change notification settings - Fork 21
[add] IT weekly pages #44
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
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9198dfa
Initial plan
Copilot a26bab4
Implement IT Weekly pages with GitHub Issues integration
Copilot b7dad36
Changes before error encountered
Copilot e2aca7a
Implement code review feedback - use RepositoryModel, add translation…
Copilot a321775
Apply suggestion from @TechQuery
TechQuery 2974d5e
Changes before error encountered
Copilot 73a9305
[optimize] upgrade to Koa 3, Sentry 10 & other latest Upstream packages
TechQuery d7b0c87
[optimize] update Wiki submodule
TechQuery 87905e0
Update components/Git/IssueCard.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import { FC, useContext } from 'react'; | ||
| import { Badge, Card } from 'react-bootstrap'; | ||
|
|
||
| import type { Issue } from '../models/Base'; | ||
| import { I18nContext } from '../models/Translation'; | ||
| import styles from '../styles/Weekly.module.less'; | ||
|
|
||
| interface IssueCardProps { | ||
| issue: Issue; | ||
| } | ||
|
|
||
| export const IssueCard: FC<IssueCardProps> = ({ issue }) => { | ||
| const { t } = useContext(I18nContext); | ||
|
|
||
| return ( | ||
| <Card className={`h-100 shadow-sm ${styles.issueCard}`}> | ||
TechQuery marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <Card.Body className="d-flex flex-column"> | ||
| <div className="d-flex justify-content-between align-items-start mb-3"> | ||
| <Badge bg={issue.state === 'open' ? 'success' : 'secondary'}> | ||
| {issue.state === 'open' ? t('open') : t('closed')} | ||
| </Badge> | ||
| <small className="text-muted">#{issue.number}</small> | ||
| </div> | ||
TechQuery marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| <Card.Title className="h5"> | ||
| <a | ||
| href={`/weekly/${issue.number}`} | ||
| className={`text-decoration-none text-dark ${styles.issueTitle}`} | ||
| > | ||
| {issue.title} | ||
| </a> | ||
| </Card.Title> | ||
|
|
||
| {issue.body && ( | ||
| <Card.Text className="text-muted mb-3 flex-grow-1"> | ||
| {issue.body.slice(0, 150)} | ||
| {issue.body.length > 150 && '...'} | ||
| </Card.Text> | ||
| )} | ||
|
|
||
| <div className="mt-auto"> | ||
| {issue.labels && issue.labels.length > 0 && ( | ||
| <div className="mb-2"> | ||
| {issue.labels.slice(0, 3).map((label, index) => ( | ||
| <Badge | ||
| key={index} | ||
| bg="light" | ||
| text="dark" | ||
| className={`me-1 ${styles.labelBadge}`} | ||
TechQuery marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| > | ||
| {typeof label === 'string' ? label : label.name} | ||
| </Badge> | ||
| ))} | ||
| {issue.labels.length > 3 && ( | ||
| <Badge bg="light" text="dark" className="small"> | ||
| +{issue.labels.length - 3} | ||
| </Badge> | ||
| )} | ||
| </div> | ||
| )} | ||
|
|
||
| <div | ||
| className={`d-flex justify-content-between align-items-center text-small text-muted ${styles.authorInfo}`} | ||
| > | ||
| <span> | ||
| {issue.user && ( | ||
| <> | ||
| {t('weekly_author')}: {issue.user.login} | ||
| </> | ||
| )} | ||
| </span> | ||
| <time dateTime={issue.created_at}> | ||
| {new Date(issue.created_at).toLocaleDateString('zh-CN')} | ||
| </time> | ||
| </div> | ||
| </div> | ||
| </Card.Body> | ||
TechQuery marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </Card> | ||
| ); | ||
| }; | ||
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
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,179 @@ | ||
| import 'github-markdown-css/github-markdown-light.css'; | ||
TechQuery marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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, Card, Container } from 'react-bootstrap'; | ||
|
|
||
| import { PageHead } from '../../components/Layout/PageHead'; | ||
| import type { Issue } from '../../models/Base'; | ||
| import { RepositoryModel } from '../../models/Base'; | ||
| import { I18nContext } from '../../models/Translation'; | ||
| import styles from '../../styles/Weekly.module.less'; | ||
|
|
||
| interface WeeklyDetailParams extends ParsedUrlQuery { | ||
| id: string; | ||
| } | ||
|
|
||
| interface WeeklyDetailProps { | ||
| issue: Issue; | ||
| } | ||
|
|
||
| export const getStaticPaths: GetStaticPaths<WeeklyDetailParams> = async () => { | ||
| const repository = new RepositoryModel('FreeCodeCamp-Chengdu'); | ||
| const repo = await repository.getOne('IT-Technology-weekly', ['issues']); | ||
|
|
||
| const paths = (repo.issues || []).map(issue => ({ | ||
| params: { id: issue.number.toString() }, | ||
| })); | ||
|
|
||
| return { paths, fallback: 'blocking' }; | ||
| }; | ||
|
|
||
| export const getStaticProps: GetStaticProps<WeeklyDetailProps, WeeklyDetailParams> = async ({ | ||
| params, | ||
| }) => { | ||
| const { id } = params!; | ||
| const repository = new RepositoryModel('FreeCodeCamp-Chengdu'); | ||
| const repo = await repository.getOne('IT-Technology-weekly', ['issues']); | ||
|
|
||
| const issue = repo.issues?.find(issue => issue.number.toString() === id); | ||
|
|
||
| if (!issue) { | ||
| return { | ||
| notFound: true, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| props: { | ||
| issue: JSON.parse(JSON.stringify(issue)), | ||
| }, | ||
| revalidate: 3600, // Revalidate every hour | ||
| }; | ||
| }; | ||
|
|
||
| const WeeklyDetailPage: FC<WeeklyDetailProps> = observer(({ issue }) => { | ||
| const { t } = useContext(I18nContext); | ||
| const htmlContent = issue.body ? (marked(issue.body) as string) : ''; | ||
TechQuery marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return ( | ||
| <Container className={`py-4 ${styles.weeklyContainer}`}> | ||
| <PageHead | ||
| title={`${issue.title} - ${t('weekly')}`} | ||
| description={issue.body ? issue.body.substring(0, 160) + '...' : issue.title} | ||
TechQuery marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /> | ||
|
|
||
| <Breadcrumb className="mb-4"> | ||
| <Breadcrumb.Item href="/">{t('home_page')}</Breadcrumb.Item> | ||
| <Breadcrumb.Item href="/weekly">{t('weekly')}</Breadcrumb.Item> | ||
| <Breadcrumb.Item active>#{issue.number}</Breadcrumb.Item> | ||
| </Breadcrumb> | ||
|
|
||
| <article> | ||
| <header className="mb-4"> | ||
| <div className="d-flex justify-content-between align-items-start mb-3"> | ||
| <Badge bg={issue.state === 'open' ? 'success' : 'secondary'} className="fs-6"> | ||
| {issue.state === 'open' ? t('open') : t('closed')} | ||
| </Badge> | ||
| <span className="text-muted">#{issue.number}</span> | ||
| </div> | ||
|
|
||
| <h1 className="display-5 mb-3">{issue.title}</h1> | ||
|
|
||
| {issue.labels?.[0] && ( | ||
| <ul className="list-unstyled mb-3"> | ||
| {issue.labels.map((label, index) => ( | ||
| <li key={index} className="d-inline-block me-2 mb-2"> | ||
| <Badge | ||
TechQuery marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| bg="light" | ||
| text="dark" | ||
| className={styles.labelBadge} | ||
| > | ||
| {typeof label === 'string' ? label : label.name} | ||
| </Badge> | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| )} | ||
|
|
||
| <dl className="row mb-4 pb-3 border-bottom"> | ||
| {issue.user && ( | ||
| <> | ||
| <dt className="col-sm-3 text-muted">{t('weekly_author')}:</dt> | ||
| <dd className="col-sm-9"> | ||
| <strong>{issue.user.login}</strong> | ||
TechQuery marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </dd> | ||
| </> | ||
| )} | ||
| {issue.created_at && ( | ||
| <> | ||
| <dt className="col-sm-3 text-muted">{t('weekly_published')}:</dt> | ||
| <dd className="col-sm-9"> | ||
| <time dateTime={issue.created_at}> | ||
| {new Date(issue.created_at).toLocaleString('zh-CN')} | ||
| </time> | ||
| </dd> | ||
| </> | ||
| )} | ||
| {issue.updated_at && issue.updated_at !== issue.created_at && ( | ||
| <> | ||
| <dt className="col-sm-3 text-muted">{t('weekly_updated')}:</dt> | ||
| <dd className="col-sm-9"> | ||
| <time dateTime={issue.updated_at}> | ||
| {new Date(issue.updated_at).toLocaleString('zh-CN')} | ||
| </time> | ||
| </dd> | ||
| </> | ||
| )} | ||
| </dl> | ||
| <div className="d-flex justify-content-end mb-4"> | ||
| <Button | ||
| variant="outline-primary" | ||
| size="sm" | ||
| href={issue.html_url} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| > | ||
| {t('view_on_github')} | ||
| </Button> | ||
| </div> | ||
| </header> | ||
|
|
||
| {htmlContent ? ( | ||
| <div | ||
| dangerouslySetInnerHTML={{ __html: htmlContent }} | ||
| className="markdown-body" | ||
| /> | ||
| ) : ( | ||
| <Card> | ||
| <Card.Body className="text-center text-muted"> | ||
| <p>{t('weekly_issue_no_content')}</p> | ||
| </Card.Body> | ||
| </Card> | ||
TechQuery marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| )} | ||
| </article> | ||
|
|
||
| <footer className="mt-5 pt-4 border-top"> | ||
| <div className="d-flex justify-content-between align-items-center"> | ||
| <Button variant="outline-secondary" href="/weekly"> | ||
| ← {t('back_to_weekly_list')} | ||
| </Button> | ||
|
|
||
| <div className="text-muted small"> | ||
| <p> | ||
| {t('github_document_description')} | ||
| <a href={issue.html_url} target="_blank" rel="noopener noreferrer" className="ms-1"> | ||
| {t('view_original_on_github')} | ||
| </a> | ||
| </p> | ||
| </div> | ||
| </div> | ||
| </footer> | ||
| </Container> | ||
| ); | ||
| }); | ||
|
|
||
| export default WeeklyDetailPage; | ||
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,82 @@ | ||
| import { observer } from 'mobx-react'; | ||
| import { GetStaticProps, InferGetStaticPropsType } from 'next'; | ||
| import { FC, useContext } from 'react'; | ||
| import { Button, Card, Col, Container, Row } from 'react-bootstrap'; | ||
|
|
||
| import { IssueCard } from '../../components/IssueCard'; | ||
| import { PageHead } from '../../components/Layout/PageHead'; | ||
| import type { Issue } from '../../models/Base'; | ||
| import { RepositoryModel } from '../../models/Base'; | ||
| import { I18nContext } from '../../models/Translation'; | ||
| import styles from '../../styles/Weekly.module.less'; | ||
|
|
||
| interface WeeklyPageProps { | ||
| issues: Issue[]; | ||
| } | ||
|
|
||
| export const getStaticProps: GetStaticProps<WeeklyPageProps> = async () => { | ||
| const repository = new RepositoryModel('FreeCodeCamp-Chengdu'); | ||
| const repo = await repository.getOne('IT-Technology-weekly', ['issues']); | ||
|
|
||
| return { | ||
| props: { | ||
| issues: JSON.parse(JSON.stringify(repo.issues || [])), | ||
| }, | ||
| revalidate: 3600, // Revalidate every hour | ||
| }; | ||
| }; | ||
|
|
||
| const WeeklyIndexPage: FC<InferGetStaticPropsType<typeof getStaticProps>> = observer( | ||
| ({ issues }) => { | ||
| const { t } = useContext(I18nContext); | ||
|
|
||
| return ( | ||
| <Container className="py-5"> | ||
| <PageHead title={t('weekly')} description={t('weekly_description')} /> | ||
|
|
||
| <div className={styles.weeklyHeader}> | ||
| <h1>{t('weekly')}</h1> | ||
| <p className="lead">{t('weekly_description')}</p> | ||
| <Button | ||
| variant="outline-light" | ||
| size="lg" | ||
| href="https://github.com/FreeCodeCamp-Chengdu/IT-Technology-weekly" | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| > | ||
| {t('view_on_github')} | ||
| </Button> | ||
| </div> | ||
|
|
||
| {issues.length > 0 ? ( | ||
| <Row xs={1} md={2} lg={3} className="g-4"> | ||
| {issues.map((issue) => ( | ||
| <Col key={issue.id}> | ||
| <IssueCard | ||
| issue={issue} | ||
| /> | ||
TechQuery marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </Col> | ||
| ))} | ||
| </Row> | ||
| ) : ( | ||
| <Card className="text-center"> | ||
| <Card.Body> | ||
| <h5>{t('no_weekly_content')}</h5> | ||
| <p className="text-muted">{t('weekly_content_from_github')}</p> | ||
| <Button | ||
| variant="primary" | ||
| href="https://github.com/FreeCodeCamp-Chengdu/IT-Technology-weekly/issues" | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| > | ||
| {t('view_all_issues')} | ||
| </Button> | ||
| </Card.Body> | ||
| </Card> | ||
| )} | ||
| </Container> | ||
| ); | ||
| }, | ||
| ); | ||
|
|
||
| export default WeeklyIndexPage; | ||
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.