Skip to content

Commit

Permalink
Merge pull request transitive-bullshit#240 from transitive-bullshit/f…
Browse files Browse the repository at this point in the history
…eature/update-2022
  • Loading branch information
transitive-bullshit authored Mar 25, 2022
2 parents c0904c8 + 7172dd0 commit 4422d44
Show file tree
Hide file tree
Showing 35 changed files with 1,111 additions and 3,250 deletions.
20 changes: 9 additions & 11 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
# @see https://github.com/rolodato/dotenv-safe for more details.
# ------------------------------------------------------------------------------

# Optional (for preview image support)
#GOOGLE_APPLICATION_CREDENTIALS=

# Optional (for preview image support)
#GCLOUD_PROJECT=

# Optional (for preview image support)
#FIREBASE_COLLECTION_IMAGES=

# Optional (for fathom analytics)
#NEXT_PUBLIC_FATHOM_ID=

# Optional (for rendering tweets efficiently)
TWITTER_ACCESS_TOKEN=
# Optional (for rendering tweets more efficiently)
#TWITTER_ACCESS_TOKEN=

# Optional (for persisting preview images to redis)
# NOTE: if you want to enable redis, only REDIS_HOST and REDIS_PASSWORD are required
#REDIS_HOST=
#REDIS_PASSWORD=
#REDIS_USER='default'
#REDIS_NAMESPACE='preview-images'
38 changes: 0 additions & 38 deletions .eslintrc

This file was deleted.

27 changes: 27 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "react", "react-hooks"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"prettier"
],
"settings": {
"react": {
"version": "detect"
}
},
"env": {
"browser": true,
"node": true
},
"rules": {
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-non-null-assertion": 0,
"@typescript-eslint/no-unused-vars": 2,
"react/prop-types": 0
}
}
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

86 changes: 0 additions & 86 deletions api/create-preview-image.ts

This file was deleted.

2 changes: 1 addition & 1 deletion components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const Footer: React.FC<{

return (
<footer className={styles.footer}>
<div className={styles.copyright}>Copyright 2021 {config.author}</div>
<div className={styles.copyright}>Copyright 2022 {config.author}</div>

{hasMounted ? (
<div className={styles.settings}>
Expand Down
115 changes: 37 additions & 78 deletions components/NotionPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react'
import Head from 'next/head'
import Link from 'next/link'
import Image from 'next/image'
import dynamic from 'next/dynamic'
import cs from 'classnames'
import { useRouter } from 'next/router'
Expand All @@ -12,12 +13,12 @@ import { PageBlock } from 'notion-types'
import { Tweet, TwitterContextProvider } from 'react-static-tweets'

// core notion renderer
import { NotionRenderer, Code, Collection, CollectionRow } from 'react-notion-x'
import { NotionRenderer } from 'react-notion-x'

// utils
import { getBlockTitle } from 'notion-utils'
import { mapPageUrl, getCanonicalPageUrl } from 'lib/map-page-url'
import { mapNotionImageUrl } from 'lib/map-image-url'
import { mapImageUrl } from 'lib/map-image-url'
import { getPageDescription } from 'lib/get-page-description'
import { getPageTweet } from 'lib/get-page-tweet'
import { searchNotion } from 'lib/search-notion'
Expand All @@ -33,43 +34,35 @@ import { PageActions } from './PageActions'
import { Footer } from './Footer'
import { PageSocial } from './PageSocial'
import { GitHubShareButton } from './GitHubShareButton'
import { ReactUtterances } from './ReactUtterances'

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

// const Code = dynamic(() =>
// import('react-notion-x').then((notion) => notion.Code)
// )
//
// const Collection = dynamic(() =>
// import('react-notion-x').then((notion) => notion.Collection)
// )
//
// const CollectionRow = dynamic(
// () => import('react-notion-x').then((notion) => notion.CollectionRow),
// {
// ssr: false
// }
// )

// TODO: PDF support via "react-pdf" package has numerous troubles building
// with next.js
// const Pdf = dynamic(
// () => import('react-notion-x').then((notion) => notion.Pdf),
// { ssr: false }
// )
// -----------------------------------------------------------------------------
// dynamic imports for optional components
// -----------------------------------------------------------------------------

const Code = dynamic(() =>
import('react-notion-x/build/third-party/code').then((m) => m.Code)
)
const Collection = dynamic(() =>
import('react-notion-x/build/third-party/collection').then(
(m) => m.Collection
)
)
const Equation = dynamic(() =>
import('react-notion-x').then((notion) => notion.Equation)
import('react-notion-x/build/third-party/equation').then((m) => m.Equation)
)
const Pdf = dynamic(
() => import('react-notion-x/build/third-party/pdf').then((m) => m.Pdf),
{
ssr: false
}
)

// we're now using a much lighter-weight tweet renderer react-static-tweets
// instead of the official iframe-based embed widget from twitter
// const Tweet = dynamic(() => import('react-tweet-embed'))

const Modal = dynamic(
() => import('react-notion-x').then((notion) => notion.Modal),
{ ssr: false }
() => import('react-notion-x/build/third-party/modal').then((m) => m.Modal),
{
ssr: false
}
)

export const NotionPage: React.FC<types.PageProps> = ({
Expand Down Expand Up @@ -131,30 +124,18 @@ export const NotionPage: React.FC<types.PageProps> = ({
const showTableOfContents = !!isBlogPost
const minTableOfContentsItems = 3

const socialImage = mapNotionImageUrl(
const socialImage = mapImageUrl(
(block as PageBlock).format?.page_cover || config.defaultPageCover,
block
)

const socialDescription =
getPageDescription(block, recordMap) ?? config.description

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

// only display comments and page actions on blog post pages
if (isBlogPost) {
if (config.utterancesGitHubRepo) {
comments = (
<ReactUtterances
repo={config.utterancesGitHubRepo}
issueMap='issue-term'
issueTerm='title'
theme={darkMode.value ? 'photon-dark' : 'github-light'}
/>
)
}

const tweet = getPageTweet(block, recordMap)
if (tweet) {
pageAside = <PageActions tweet={tweet} />
Expand Down Expand Up @@ -225,52 +206,30 @@ export const NotionPage: React.FC<types.PageProps> = ({
pageId === site.rootNotionPageId && 'index-page'
)}
components={{
pageLink: ({
href,
as,
passHref,
prefetch,
replace,
scroll,
shallow,
locale,
...props
}) => (
<Link
href={href}
as={as}
passHref={passHref}
prefetch={prefetch}
replace={replace}
scroll={scroll}
shallow={shallow}
locale={locale}
>
<a {...props} />
</Link>
),
code: Code,
collection: Collection,
collectionRow: CollectionRow,
tweet: Tweet,
modal: Modal,
equation: Equation
nextImage: Image,
nextLink: Link,
Code,
Collection,
Equation,
Pdf,
Modal,
Tweet
}}
recordMap={recordMap}
rootPageId={site.rootNotionPageId}
rootDomain={site.domain}
fullPage={!isLiteMode}
darkMode={darkMode.value}
previewImages={site.previewImages !== false}
previewImages={!!recordMap.preview_images}
showCollectionViewDropdown={false}
showTableOfContents={showTableOfContents}
minTableOfContentsItems={minTableOfContentsItems}
defaultPageIcon={config.defaultPageIcon}
defaultPageCover={config.defaultPageCover}
defaultPageCoverPosition={config.defaultPageCoverPosition}
mapPageUrl={siteMapPageUrl}
mapImageUrl={mapNotionImageUrl}
mapImageUrl={mapImageUrl}
searchNotion={searchNotion}
pageFooter={comments}
pageAside={pageAside}
footer={
<Footer
Expand Down
3 changes: 2 additions & 1 deletion components/Page404.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export const Page404: React.FC<types.PageProps> = ({ site, pageId, error }) => {
) : (
pageId && (
<p>
Make sure that Notion page "{pageId}" is publicly accessible.
Make sure that Notion page &quot;{pageId}&quot; is publicly
accessible.
</p>
)
)}
Expand Down
Loading

0 comments on commit 4422d44

Please sign in to comment.