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

Investigating Preview #16

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 4 additions & 1 deletion pages/[...wordpressNode].js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ export default function Page(props) {
}

export async function getStaticProps(ctx) {
return { ...(await getWordPressProps({ ctx })), revalidate: 1 }
return {
...(await getWordPressProps({ ctx })),
revalidate: 1
}
}

export async function getStaticPaths() {
Expand Down
2 changes: 1 addition & 1 deletion pages/api/faust/[[...route]].js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'faust.config'
import '../../../faust.config'
import { apiRouter } from '@faustwp/core'

export default apiRouter
12 changes: 6 additions & 6 deletions wp-templates/IndexTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { Layout } from '@/components/Layout'
import blocks from '@/wp-blocks'

export const IndexTemplate = ({ data }) => {
const { node } = data
const myNode = data?.node

if (!node) {
if (!myNode) {
return null
}

const { editorBlocks } = node
const { editorBlocks } = myNode

let toc = []

Expand Down Expand Up @@ -48,15 +48,15 @@ export const IndexTemplate = ({ data }) => {

return (
<Layout
title={node?.title ? node.title : 'WPGraphQL for ACF'}
title={myNode?.title ? myNode.title : 'WPGraphQL for ACF'}
data={data}
navigation={data?.navigation?.nodes}
toc={toc}
>
{node?.modified && (
{myNode?.modified && (
<div id="last-updated" className="text-sm text-gray-500">
Last Upated:{' '}
{new Date(node.modified).toLocaleDateString('en-us', {
{new Date(myNode.modified).toLocaleDateString('en-us', {
weekday: 'long',
year: 'numeric',
month: 'short',
Expand Down
4 changes: 3 additions & 1 deletion wp-templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { ArchiveFieldType } from './archive-field_type'
import { FrontPage } from './front-page'
import { IndexTemplate } from './IndexTemplate'
import { SingleFieldType } from './single-field_type'
import { Singular } from './singular'

const templates = {
index: IndexTemplate,
'singular': Singular,
'single-field_type': SingleFieldType,
'archive-field_type': ArchiveFieldType,
'front-page': FrontPage,
'archive': Archive,
index: IndexTemplate,
}

export default templates
128 changes: 128 additions & 0 deletions wp-templates/singular.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { gql } from '@apollo/client'
import { WordPressBlocksViewer } from '@faustwp/blocks'
import { flatListToHierarchical } from '@faustwp/core'

import { Layout } from '@/components/Layout'
import blocks from '@/wp-blocks'

export const Singular = ({ data }) => {
const myNode = data?.node

if (!myNode) {
return null
}

const { editorBlocks } = myNode

let toc = []

editorBlocks &&
editorBlocks.map((block) => {
if (!block.attributes || !block.attributes.level) {
return null
}

if (block.attributes.level === 2 || block.attributes.level === 3) {
let heading = {
tagName: `h${block.attributes.level}`,
children: [
{
type: 'text',
value: block.attributes.content,
},
],
}
toc.push(heading)
}
})

const blockList = flatListToHierarchical(editorBlocks, {
childrenKey: 'innerBlocks',
})

// eslint-disable-next-line no-console
console.log({
editorBlocks,
blockList,
})

return (
<Layout
title={node?.title ? node.title : 'WPGraphQL for ACF'}
data={data}
navigation={data?.navigation?.nodes}
toc={toc}
>
{node?.modified && (
<div id="last-updated" className="text-sm text-gray-500">
Last Upated:{' '}
{new Date(node.modified).toLocaleDateString('en-us', {
weekday: 'long',
year: 'numeric',
month: 'short',
day: 'numeric',
})}
</div>
)}
<WordPressBlocksViewer blocks={blockList} />
</Layout>
)
}

Singular.query = gql`
query SingularTemplate($id: ID!, $asPreview: Boolean = false) {
node: post(id: $id, idType: URI, asPreview: $asPreview) {
__typename
uri
...on NodeWithTitle {
title
}
...on NodeWithEditorBlocks {
editorBlocks {
__typename
name
renderedHtml
id: clientId
parentId: parentClientId
...${blocks.CoreParagraph.fragments.key}
...${blocks.CoreColumns.fragments.key}
...${blocks.CoreColumn.fragments.key}
...${blocks.CoreCode.fragments.key}
...${blocks.CoreButtons.fragments.key}
...${blocks.CoreButton.fragments.key}
...${blocks.CoreQuote.fragments.key}
...${blocks.CoreImage.fragments.key}
...${blocks.CoreSeparator.fragments.key}
...${blocks.CoreList.fragments.key}
...${blocks.CoreHeading.fragments.key}
}
}
...on ContentNode {
modified
...on NodeWithContentEditor {
content
}
}
}
...LayoutFragment
}
${blocks.CoreParagraph.fragments.entry}
${blocks.CoreColumns.fragments.entry}
${blocks.CoreColumn.fragments.entry}
${blocks.CoreCode.fragments.entry}
${blocks.CoreButtons.fragments.entry}
${blocks.CoreButton.fragments.entry}
${blocks.CoreQuote.fragments.entry}
${blocks.CoreImage.fragments.entry}
${blocks.CoreSeparator.fragments.entry}
${blocks.CoreList.fragments.entry}
${blocks.CoreHeading.fragments.entry}
${Layout.fragment}
`

Singular.variables = ({ uri, asPreview }) => {
return {
id: uri,
asPreview
}
}