Skip to content
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

Add Disqus Comments, Google Analytics, and Privacy Policy support #412

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Squashed commit of the following:
commit c638fb2
Author: Randall Hand <[email protected]>
Date:   Fri Nov 25 10:58:01 2022 -0500

    Add privacy policy in footer

commit fce5457
Author: Randall Hand <[email protected]>
Date:   Thu Nov 24 15:19:34 2022 -0500

    Added disqus_recommendations

commit 33f5b46
Author: Randall Hand <[email protected]>
Date:   Sun Nov 20 14:29:00 2022 -0500

    Moved GA code outside of useEffect

commit 6300ca3
Author: Randall Hand <[email protected]>
Date:   Sun Nov 20 12:10:57 2022 -0500

    Simplified GA PageView tracking

commit 338ed22
Author: Randall Hand <[email protected]>
Date:   Sun Nov 20 11:53:21 2022 -0500

    BugFix for type conversion : First launch was a boolean

commit 0b676e0
Author: Randall Hand <[email protected]>
Date:   Sun Nov 20 11:44:35 2022 -0500

    Removed unnecessary debug output

commit 8163059
Author: Randall Hand <[email protected]>
Date:   Sun Nov 20 11:43:14 2022 -0500

    Removing debug output

commit 6d99289
Author: Randall Hand <[email protected]>
Date:   Sun Nov 20 10:53:50 2022 -0500

    Improved nav bar

commit bc278a7
Author: Randall Hand <[email protected]>
Date:   Sun Nov 20 10:30:33 2022 -0500

    Switch from react-ga to react-ga4

commit 2df7dee
Author: Randall Hand <[email protected]>
Date:   Sun Nov 20 09:58:31 2022 -0500

    Added in params for GA & Disqus

commit 138eb7c
Author: Randall Hand <[email protected]>
Date:   Sat Nov 19 19:34:38 2022 -0500

    New file - copy of other

commit 90d5720
Author: Randall Hand <[email protected]>
Date:   Sat Nov 19 19:33:23 2022 -0500

    Added 'post' dir

commit 150a16e
Author: Randall Hand <[email protected]>
Date:   Sat Nov 19 18:52:15 2022 -0500

    Fix for blank blocks

commit 8cbd304
Author: Randall Hand <[email protected]>
Date:   Sat Nov 19 18:21:09 2022 -0500

    Fix disqus args

commit 6babc33
Author: Randall Hand <[email protected]>
Date:   Sat Nov 19 18:05:54 2022 -0500

    Remove GitHubShare button

commit 0cbf6b9
Merge: 9ea1b3c 5446dcc
Author: Randall Hand <[email protected]>
Date:   Sat Nov 19 18:01:18 2022 -0500

    Merge pull request #1 from Yeraze/add_disqus

    Add disqus

commit 5446dcc
Author: Randall Hand <[email protected]>
Date:   Sat Nov 19 17:52:28 2022 -0500

    Added in Disqus Comments (maybe?)

commit 6c4ae97
Author: Randall Hand <[email protected]>
Date:   Sat Nov 19 12:02:11 2022 -0500

    Initial config commit
  • Loading branch information
Yeraze committed Nov 25, 2022
commit 9b8356c68373a4705d0f346fc5489d96edb1570a
14 changes: 13 additions & 1 deletion components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import * as config from '@/lib/config'
import { useDarkMode } from '@/lib/use-dark-mode'

import styles from './styles.module.css'
import { useNotionContext } from 'react-notion-x'

// TODO: merge the data and icons from PageSocial with the social links in Footer

export const FooterImpl: React.FC = () => {
const [hasMounted, setHasMounted] = React.useState(false)
const { isDarkMode, toggleDarkMode } = useDarkMode()
const { mapPageUrl } = useNotionContext()

const onToggleDarkMode = React.useCallback(
(e) => {
Expand All @@ -36,7 +38,17 @@ export const FooterImpl: React.FC = () => {
return (
<footer className={styles.footer}>
<div className={styles.copyright}>Copyright 2022 {config.author}</div>

{config.privacyPolicy && (
<a
className={styles.copyright}
href={mapPageUrl(config.privacyPolicy)}
title='Privacy Policy'
target='_blank'
rel='noopener noreferrer'
>
Privacy Policy
</a>
)}
<div className={styles.settings}>
{hasMounted && (
<a
Expand Down
22 changes: 18 additions & 4 deletions components/NotionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import { PageAside } from './PageAside'
import { PageHead } from './PageHead'
import styles from './styles.module.css'

import { DiscussionEmbed } from 'disqus-react';


// -----------------------------------------------------------------------------
// dynamic imports for optional components
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -80,6 +83,7 @@ const Collection = dynamic(() =>
const Equation = dynamic(() =>
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),
{
Expand Down Expand Up @@ -165,7 +169,7 @@ export const NotionPage: React.FC<types.PageProps> = ({
propertyLastEditedTimeValue,
propertyTextValue,
propertyDateValue
}),
}),
[]
)

Expand Down Expand Up @@ -210,6 +214,8 @@ export const NotionPage: React.FC<types.PageProps> = ({
return <Page404 site={site} pageId={pageId} error={error} />
}

const canonicalPageUrl =
!config.isDev && getCanonicalPageUrl(site, recordMap)(pageId)
const title = getBlockTitle(block, recordMap) || site.name

console.log('notion page', {
Expand All @@ -228,9 +234,6 @@ export const NotionPage: React.FC<types.PageProps> = ({
g.block = block
}

const canonicalPageUrl =
!config.isDev && getCanonicalPageUrl(site, recordMap)(pageId)

const socialImage = mapImageUrl(
getPageProperty<string>('Social Image', block, recordMap) ||
(block as PageBlock).format?.page_cover ||
Expand All @@ -242,6 +245,16 @@ export const NotionPage: React.FC<types.PageProps> = ({
getPageProperty<string>('Description', block, recordMap) ||
config.description


const disqus =<DiscussionEmbed
shortname={config.disqusShortname}
config={ {
url: (canonicalPageUrl ? canonicalPageUrl : ""),
title: title
} }
/>


return (
<>
<PageHead
Expand Down Expand Up @@ -278,6 +291,7 @@ export const NotionPage: React.FC<types.PageProps> = ({
mapImageUrl={mapImageUrl}
searchNotion={config.isSearchEnabled ? searchNotion : null}
pageAside={pageAside}
pageFooter={pageId === site.rootNotionPageId ? null : (config.disqusShortname ? disqus : null)}
footer={footer}
/>

Expand Down
1 change: 1 addition & 0 deletions components/PageActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const PageActions: React.FC<{ tweet: string }> = ({ tweet }) => {
>
<AiOutlineRetweet />
</a>

</div>
)
}
7 changes: 6 additions & 1 deletion lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const youtube: string | null = getSiteConfig('youtube', null)
export const linkedin: string | null = getSiteConfig('linkedin', null)
export const newsletter: string | null = getSiteConfig('newsletter', null)
export const zhihu: string | null = getSiteConfig('zhihu', null)

export const privacyPolicy : string | null = getSiteConfig('privacyPolicy', null)
export const getMastodonHandle = (): string | null => {
if (!mastodon) {
return null
Expand Down Expand Up @@ -109,6 +109,9 @@ export const navigationLinks: Array<NavigationLink | null> = getSiteConfig(
null
)

export const googleAnalyticsId : string | null = getSiteConfig('googleAnalyticsId', null)
export const disqusShortname : string | null = getSiteConfig('disqusShortname', null)

// Optional site search
export const isSearchEnabled: boolean = getSiteConfig('isSearchEnabled', true)

Expand Down Expand Up @@ -167,6 +170,8 @@ export const fathomConfig = fathomId
}
: undefined



export const posthogId = process.env.NEXT_PUBLIC_POSTHOG_ID
export const posthogConfig: posthog.Config = {
api_host: 'https://app.posthog.com'
Expand Down
4 changes: 2 additions & 2 deletions lib/map-page-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const mapPageUrl =
return createUrl('/', searchParams)
} else {
return createUrl(
`/${getCanonicalPageId(pageUuid, recordMap, { uuid })}`,
`/post/${getCanonicalPageId(pageUuid, recordMap, { uuid })}`,
searchParams
)
}
Expand All @@ -32,7 +32,7 @@ export const getCanonicalPageUrl =
if (uuidToId(pageId) === site.rootNotionPageId) {
return `https://${site.domain}`
} else {
return `https://${site.domain}/${getCanonicalPageId(pageUuid, recordMap, {
return `https://${site.domain}/post/${getCanonicalPageId(pageUuid, recordMap, {
uuid
})}`
}
Expand Down
7 changes: 5 additions & 2 deletions lib/resolve-notion-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ export async function resolveNotionPage(domain: string, rawPageId?: string) {
let recordMap: ExtendedRecordMap

if (rawPageId && rawPageId !== 'index') {
pageId = parsePageId(rawPageId)

if (rawPageId.substring(0,5) === "post/") {
pageId = parsePageId(rawPageId.substring(6))
} else {
pageId = parsePageId(rawPageId)
}
if (!pageId) {
// check if the site configuration provides an override or a fallback for
// the page's URI
Expand Down
4 changes: 4 additions & 0 deletions lib/site-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export interface SiteConfig {
youtube?: string
zhihu?: string
mastodon?: string;
privacyPolicy?: string;

googleAnalyticsId?: string | null
disqusShortname?: string | null

defaultPageIcon?: string | null
defaultPageCover?: string | null
Expand Down
Loading