Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
renzholy committed Jun 20, 2021
1 parent 97a5d33 commit 593a61e
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 62 deletions.
6 changes: 6 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
NEXT_PUBLIC_REPOSITORY=renzholy/renzholy.github.io
NEXT_PUBLIC_REF=refs/heads/main
NEXT_PUBLIC_INDEX=/readme
NEXT_PUBLIC_TITLE=Found Pan Tiger
NEXT_PUBLIC_HEADER=About,/about
NEXT_PUBLIC_FOOTER=GitHub,https://github.com/renzholy;Twitter,http://twitter.com/rezholy;Jike,https://web.okjike.com/u/d25026f2-18ce-48aa-9ea7-c05a25446368
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Environments:
- GITHUB_TOKEN
- NEXT_PUBLIC_TITLE
- NEXT_PUBLIC_INDEX
- NEXT_PUBLIC_LINKS
- NEXT_PUBLIC_HEADER
- NEXT_PUBLIC_FOOTER

Todos:

Expand Down
68 changes: 68 additions & 0 deletions components/footer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { css } from '@linaria/core'
import { useMemo } from 'react'
import Link from 'next/link'

export default function Footer() {
const footers = useMemo(
() =>
process.env.NEXT_PUBLIC_FOOTER?.split(';').map((item) =>
item.split(','),
) || [],
[],
)

return (
<footer
className={css`
user-select: none;
display: flex;
align-items: center;
padding: 32px 20px;
border-top: 1px solid #e1e4e8;
span {
color: #586069;
font-size: 12px;
}
a {
color: #0366d6;
text-decoration: none;
font-size: 12px;
}
a + a {
margin-left: 16px;
}
a:hover,
a:focus {
text-decoration: underline;
}
`}>
<span>
Generated by:&nbsp;
<a
href="https://github.com/renzholy/blogit"
target="_blank"
rel="noreferrer">
Blogit
</a>
</span>
<span
className={css`
flex: 1;
`}
/>
{footers.map(([name, href]) =>
href.startsWith('http') || href.startsWith('//') ? (
<a key={name} href={href} target="_blank" rel="noreferrer">
{name}
</a>
) : (
<Link
key={name}
href={href === process.env.NEXT_PUBLIC_INDEX ? '/' : href}>
{name}
</Link>
),
)}
</footer>
)
}
5 changes: 3 additions & 2 deletions components/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { css } from '@linaria/core'
import { ReactNode } from 'react'

import Footer from './footer'
import Navigation from './navigation'

export default function Layout(props: { children: ReactNode }) {
Expand All @@ -14,10 +14,11 @@ export default function Layout(props: { children: ReactNode }) {
right: 0;
height: 64px;
background-color: #24292e;
padding: 0 32px;
padding: 0 20px;
`}
/>
{props.children}
<Footer />
</>
)
}
5 changes: 2 additions & 3 deletions components/markdown-render.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ReactNode, useMemo } from 'react'
import { cx } from '@linaria/core'

import { preview } from '../themes/github'
import { process } from '../libs/markdown'
import { preview } from 'themes/github'
import { process } from 'libs/markdown'

export default function MarkdownRender(props: {
className?: string
Expand Down
3 changes: 1 addition & 2 deletions components/mona-code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import useAsyncEffect from 'use-async-effect'
import rehype2react, { ComponentProps } from 'rehype-react'
import unified from 'unified'
import rehype from 'rehype-parse'

import { useMonacoColor } from '../hooks/use-monaco'
import { useMonacoColor } from 'hooks/use-monaco'

const map: { [key: string]: string } = {
js: 'javascript',
Expand Down
37 changes: 19 additions & 18 deletions components/navigation.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { css, cx } from '@linaria/core'
import Link from 'next/link'
import { useMemo } from 'react'

export default function Navigation(props: { className?: string }) {
const links =
process.env.NEXT_PUBLIC_LINKS?.split(';').map((item) => item.split(',')) ||
[]
const headers = useMemo(
() =>
process.env.NEXT_PUBLIC_HEADER?.split(';').map((item) =>
item.split(','),
) || [],
[],
)

return (
<nav
Expand All @@ -29,29 +34,25 @@ export default function Navigation(props: { className?: string }) {
}
`,
)}>
{links
.filter(
([, link]) => !link.startsWith('http') && !link.startsWith('//'),
)
.map(([name, href]) => (
<Link
key={name}
href={href === process.env.NEXT_PUBLIC_INDEX ? '/' : href}>
{name}
</Link>
))}
<Link href="/">{process.env.NEXT_PUBLIC_TITLE}</Link>
<div
className={css`
flex: 1;
`}
/>
{links
.filter(([, link]) => link.startsWith('http') || link.startsWith('//'))
.map(([name, href]) => (
{headers.map(([name, href]) =>
href.startsWith('http') || href.startsWith('//') ? (
<a key={name} href={href} target="_blank" rel="noreferrer">
{name}
</a>
))}
) : (
<Link
key={name}
href={href === process.env.NEXT_PUBLIC_INDEX ? '/' : href}>
{name}
</Link>
),
)}
</nav>
)
}
3 changes: 3 additions & 0 deletions components/utterances.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export default function Utterances() {
ref={ref}
className={css`
user-select: none;
border-top: 1px solid #e1e4e8;
padding: 16px;
min-height: 270px;
.utterances {
max-width: var(--max-width);
}
Expand Down
3 changes: 1 addition & 2 deletions hooks/use-monaco.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { useEffect } from 'react'
import IDLE from 'monaco-themes/themes/IDLE.json'
import emojis from 'node-emoji'
import type { editor } from 'monaco-editor/esm/vs/editor/editor.api'

import { id, language, conf } from '../libs/monaco-config'
import { id, language, conf } from 'libs/monaco-config'

export function useMonacoColor() {
const monaco = useMonaco()
Expand Down
7 changes: 3 additions & 4 deletions libs/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import sanitize from 'rehype-sanitize'
import rehype2react from 'rehype-react'
import type { H } from 'mdast-util-to-hast'
import type { Node } from 'unist'

import MonaCode from 'components/mona-code'
import LocalImage from 'components/local-image'
import LocalLink from 'components/local-link'
import { emoji } from './plugins/emoji'
import MonaCode from '../components/mona-code'
import LocalImage from '../components/local-image'
import LocalLink from '../components/local-link'

function handleHtml(_h: H, node: Node) {
return (
Expand Down
48 changes: 21 additions & 27 deletions pages/[[...path]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import { Octokit } from 'octokit'
import dayjs from 'dayjs'
import Head from 'next/head'
import { useMemo } from 'react'

import MarkdownRender from '../components/markdown-render'
import Utterances from '../components/utterances'
import MarkdownRender from 'components/markdown-render'
import Utterances from 'components/utterances'

const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
Expand Down Expand Up @@ -40,36 +39,31 @@ export default function Path(props: Props) {
}.png?size=128`}
/>
</Head>
<div
<MarkdownRender
className={css`
margin: 96px auto 32px;
max-width: var(--max-width);
padding: 0 16px;
`}>
<MarkdownRender
{props.data}
</MarkdownRender>
{props.lastModified ? (
<footer
className={css`
padding: 0;
margin: 16px auto;
padding: 0 20px;
max-width: var(--max-width);
font-size: 14px;
color: #6a737d;
display: flex;
justify-content: flex-end;
`}>
{props.data}
</MarkdownRender>
{props.lastModified ? (
<footer
className={css`
border-bottom: 1px solid #eaecef;
padding: 16px 0;
font-size: 14px;
color: #6a737d;
display: flex;
justify-content: flex-end;
`}>
last modified:&nbsp;
<time title={props.lastModified}>
{dayjs(props.lastModified).format('YYYY-MM-DD')}
</time>
</footer>
) : null}
<Utterances />
</div>
Last modified:&nbsp;
<time title={props.lastModified}>
{dayjs(props.lastModified).format('YYYY-MM-DD')}
</time>
</footer>
) : null}
<Utterances />
</>
)
}
Expand Down
3 changes: 1 addition & 2 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import React from 'react'
import type { AppProps } from 'next/app'
import Layout from 'components/layout'
import 'normalize.css'

import Layout from '../components/layout'
import './global.css'

function MyApp({ Component, pageProps }: AppProps) {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "esnext"
"target": "esnext",
"baseUrl": "."
},
"exclude": ["node_modules"],
"include": ["**/*.ts", "**/*.tsx", "next.config.js", "workers"]
Expand Down

0 comments on commit 593a61e

Please sign in to comment.