Skip to content

Commit

Permalink
Merge branch 'transitive-bullshit' of https://ghproxy.com/github.com/…
Browse files Browse the repository at this point in the history
  • Loading branch information
fky2015 committed Apr 8, 2022
2 parents 5b2580c + 70ea312 commit 88e3734
Show file tree
Hide file tree
Showing 18 changed files with 515 additions and 56 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ jobs:

- run: yarn install --frozen-lockfile
- name: build
# TODO Enable those lines below if you use a Redis cache, you'll also need to configure GitHub Repository Secrets
# env:
# REDIS_HOST: ${{ secrets.REDIS_HOST }}
# REDIS_PASSWORD: ${{ secrets.REDIS_PASSWORD }}
env:
REDIS_HOST: ${{ secrets.REDIS_HOST }}
REDIS_PASSWORD: ${{ secrets.REDIS_PASSWORD }}
run: yarn build
137 changes: 137 additions & 0 deletions components/HeroHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import React, { Component } from 'react'

import raf from 'raf'
import random from 'random'

import FluidAnimation from 'react-fluid-animation'

const exp = random.exponential()
const numSplatsPerEpoch = 1
const minSplatRadius = 0.01
const maxSplatRadius = 0.03

export class HeroHeader extends Component<{
className?: string
}> {
_time: number = Date.now()
_direction: number
_tickRaf: any
_timeout: any
_animation: any

componentDidMount() {
this._time = Date.now()
this._direction = 1
this._reset()
this._tick()
}

componentWillUnmount() {
if (this._tickRaf) {
raf.cancel(this._tickRaf)
this._tickRaf = null
}

if (this._timeout) {
clearTimeout(this._timeout)
this._timeout = null
}
}

render() {
return (
<FluidAnimation
className={this.props.className}
animationRef={this._animationRef}
/>
)
}

_animationRef = (ref) => {
this._animation = ref
this._reset()
}

_reset() {
if (this._animation) {
this._animation.config.splatRadius = random.float(
minSplatRadius,
maxSplatRadius
)
this._animation.addRandomSplats(random.int(100, 180))
}
}

_tick = () => {
this._tickRaf = null
this._timeout = null

let scale = 1.0

if (this._animation) {
const w = this._animation.width
const h = this._animation.height

// adjust the intensity scale depending on the canvas width, so it's less
// intense on smaller screens
const s = Math.max(0.1, Math.min(1, w / 1200))
scale = Math.pow(s, 1.2)

this._animation.config.splatRadius = random.float(
minSplatRadius * scale,
maxSplatRadius * scale
)

const splats = []
for (let i = 0; i < numSplatsPerEpoch; ++i) {
const color = [random.float(10), random.float(10), random.float(10)]

const w0 = w / 3.0
const w1 = (w * 2.0) / 3.0

const h0 = h / 3.0
const h1 = (h * 2.0) / 3.0

// eslint-disable-next-line no-constant-condition
while (true) {
const x = random.float(w)
const y = random.float(h)

// favor uniformly distributed samples within the center-ish of the canvas
if (x > w0 && x < w1 && y > h0 && y < h1) {
continue
}

const dx = random.float(-1, 1) * random.float(200, 3000) * scale
const dy = random.float(-1, 1) * random.float(200, 3000) * scale
const splat = { x, y, dx, dy, color }
splats.push(splat)
break
}

// old version which generated samples along a circle
// const t = random.float(2 * Math.PI)
// const cos = Math.cos(t)
// const sin = Math.sin(t)
// const x = w / 2 + r * cos
// const y = h / 2 + r * sin + yOffset
// const k = random.float() > 0.98 ? random.float(3, 10) : 1
// const dx = k * random.float(-1, 1) * random.float(50, 300) * cos
// const dy = k * random.float(-1, 1) * random.float(50, 300) * sin
// const splat = { x, y, dx, dy, color }
// splats.push(splat)
}

this._animation.addSplats(splats)
}

// using an exponential distribution here allows us to favor bursts of activity
// but also allow for more occasional pauses
const dampenedScale = Math.pow(scale, 0.2)
const timeout = (exp() * 100) / dampenedScale

this._timeout = setTimeout(() => {
this._tickRaf = raf(this._tick)
}, timeout)
}
}
53 changes: 48 additions & 5 deletions components/NotionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import { Tweet, TwitterContextProvider } from 'react-static-tweets'
import { NotionRenderer } from 'react-notion-x'

// utils
import { getBlockTitle, getPageProperty } from 'notion-utils'
import {
getBlockTitle,
getPageProperty,
parsePageId,
normalizeTitle
} from 'notion-utils'
import { mapPageUrl, getCanonicalPageUrl } from 'lib/map-page-url'
import { mapImageUrl } from 'lib/map-image-url'
import { getPageTweet } from 'lib/get-page-tweet'
Expand All @@ -34,6 +39,7 @@ import { PageSocial } from './PageSocial'
const ReactGiscus = dynamic(() => import('./ReactGiscus'))
import { NotionPageHeader } from './NotionPageHeader'
import { GitHubShareButton } from './GitHubShareButton'
import { HeroHeader } from './HeroHeader'

import styles from './styles.module.css'

Expand Down Expand Up @@ -69,11 +75,30 @@ const Modal = dynamic(
}
)

const propertySelectValue = (
{ schema, value, key, pageHeader },
defaultFn: () => React.ReactNode
) => {
value = normalizeTitle(value)

if (pageHeader && schema.type === 'multi_select' && value) {
return (
<Link href={`/tags/${value}`} key={key}>
<a>{defaultFn()}</a>
</Link>
)
}

return defaultFn()
}

export const NotionPage: React.FC<types.PageProps> = ({
site,
recordMap,
error,
pageId
pageId,
tagsPage,
propertyToFilterName
}) => {
const router = useRouter()
const lite = useSearchParam('lite')
Expand All @@ -88,7 +113,9 @@ export const NotionPage: React.FC<types.PageProps> = ({
Pdf,
Modal,
Tweet,
Header: NotionPageHeader
Header: NotionPageHeader,

propertySelectValue
}),
[]
)
Expand Down Expand Up @@ -131,7 +158,9 @@ export const NotionPage: React.FC<types.PageProps> = ({
return <Page404 site={site} pageId={pageId} error={error} />
}

const title = getBlockTitle(block, recordMap) || site.name
const name = getBlockTitle(block, recordMap) || site.name
const title =
tagsPage && propertyToFilterName ? `${propertyToFilterName} ${name}` : name

if (!config.isServer) {
// add important objects to the window global for easy debugging
Expand All @@ -148,6 +177,9 @@ export const NotionPage: React.FC<types.PageProps> = ({
// parsePageId(block.id) === parsePageId(site.rootNotionPageId)
const isBlogPost =
block.type === 'page' && block.parent_table === 'collection'
const isBioPage =
parsePageId(block.id) === parsePageId('8d0062776d0c4afca96eb1ace93a7538')

const showTableOfContents = !!isBlogPost
const minTableOfContentsItems = 3

Expand All @@ -164,6 +196,7 @@ export const NotionPage: React.FC<types.PageProps> = ({

let comments: React.ReactNode = null
let pageAside: React.ReactNode = null
let pageCover: React.ReactNode = null

// only display comments and page actions on blog post pages
if (isBlogPost) {
Expand All @@ -180,6 +213,12 @@ export const NotionPage: React.FC<types.PageProps> = ({
pageAside = <PageSocial />
}

if (isBioPage) {
pageCover = (
<HeroHeader className='notion-page-cover-wrapper notion-page-cover-hero' />
)
}

return (
<TwitterContextProvider value={twitterContextValue}>
<PageHead
Expand All @@ -198,7 +237,8 @@ export const NotionPage: React.FC<types.PageProps> = ({
<NotionRenderer
bodyClassName={cs(
styles.notion,
pageId === site.rootNotionPageId && 'index-page'
pageId === site.rootNotionPageId && 'index-page',
tagsPage && 'tags-page'
)}
components={components}
recordMap={recordMap}
Expand All @@ -213,12 +253,15 @@ export const NotionPage: React.FC<types.PageProps> = ({
defaultPageIcon={config.defaultPageIcon}
defaultPageCover={config.defaultPageCover}
defaultPageCoverPosition={config.defaultPageCoverPosition}
linkTableTitleProperties={false}
mapPageUrl={siteMapPageUrl}
mapImageUrl={mapImageUrl}
pageFooter={comments}
searchNotion={config.isSearchEnabled ? searchNotion : null}
pageAside={pageAside}
footer={<Footer />}
pageTitle={tagsPage && propertyToFilterName ? title : undefined}
pageCover={pageCover}
/>

<GitHubShareButton />
Expand Down
3 changes: 3 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Suggestions and pull requests are highly encouraged. Have a look at the [open is

## Development

**If your feature/fix/issue is related to some basic feature provided by Starter Kit, follow the guide below. (recommended)**
**Otherwise, you can use same way to develop `https://github.com/fky2015/nexon`**

To develop the project locally, you'll need a recent version of Node.js and `yarn` v1 installed globally.

To get started, clone the repo and run `yarn` from the root directory:
Expand Down
2 changes: 2 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export interface PageProps {
recordMap?: ExtendedRecordMap
pageId?: string
error?: PageError
tagsPage?: boolean
propertyToFilterName?: string | string
}

export interface Model {
Expand Down
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "nextjs-notion-starter-kit",
"name": "nexon",
"version": "2.0.0",
"private": true,
"description": "The perfect starter kit for building beautiful websites with Next.js and Notion.",
"author": "Travis Fischer <travis@transitivebullsh.it>",
"repository": "transitive-bullshit/nextjs-notion-starter-kit",
"author": "Feng Kaiyu <loveress01@outlook.com>",
"repository": "fky2015/nexon",
"license": "MIT",
"engines": {
"node": ">=14.17"
Expand Down Expand Up @@ -35,6 +35,7 @@
"fathom-client": "^3.4.1",
"got": "^12.0.3",
"isomorphic-unfetch": "^3.1.0",
"lodash.omit": "^4.5.0",
"lqip-modern": "^1.2.0",
"next": "^12.1.1",
"next-compose-plugins": "^2.2.1",
Expand All @@ -47,10 +48,13 @@
"p-map": "^5.3.0",
"p-memoize": "^6.0.1",
"posthog-js": "^1.20.2",
"raf": "^3.4.1",
"random": "^3.0.6",
"react": "^17.0.2",
"react-body-classname": "^1.3.1",
"react-dom": "^17.0.2",
"react-notion-x": "^6.8.4",
"react-fluid-animation": "^1.0.1",
"react-static-tweets": "^0.7.2",
"react-use": "^17.3.2",
"static-tweets": "^0.7.2",
Expand All @@ -59,6 +63,7 @@
},
"devDependencies": {
"@next/bundle-analyzer": "^12.1.0",
"@types/lodash.omit": "^4.5.6",
"@types/node": "^17.0.23",
"@types/node-fetch": "^3.0.3",
"@types/react": "^17.0.31",
Expand Down
2 changes: 0 additions & 2 deletions pages/[pageId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export const getStaticProps = async ({ params }) => {
try {
const props = await resolveNotionPage(domain, rawPageId)

//console.log('props == ', props)

return { props, revalidate: 10 }
} catch (err) {
console.error('page error', domain, rawPageId, err)
Expand Down
14 changes: 12 additions & 2 deletions pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@ export default class MyDocument extends Document {
rel='icon'
type='image/png'
sizes='32x32'
href='favicon.png'
href='favicon-32x32.png'
/>
<link
rel='apple-touch-icon'
sizes='180x180'
href='/apple-touch-icon.png'
/>
<link
rel='icon'
type='image/png'
sizes='96x96'
href='/favicon-96x96.png'
/>

<link rel='manifest' href='/manifest.json' />
</Head>

Expand Down
2 changes: 1 addition & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const getStaticProps = async () => {
try {
const props = await resolveNotionPage(domain)

return { props, revalidate: 10 }
return { props, revalidate: 60 }
} catch (err) {
console.error('page error', domain, err)

Expand Down
7 changes: 5 additions & 2 deletions pages/robots.txt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ export const getServerSideProps: GetServerSideProps = async ({ req, res }) => {
}
}

// cache for up to one day
res.setHeader('Cache-Control', 'public, max-age=86400, immutable')
// cache at vercel edge for up to one day
res.setHeader(
'Cache-Control',
'max-age=0, s-maxage=86400, stale-while-revalidate=3600'
)
res.setHeader('Content-Type', 'text/plain')

// only allow the site to be crawlable on the production deployment
Expand Down
Loading

0 comments on commit 88e3734

Please sign in to comment.