-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add netlify partial component (#2134)
* feat: add netlify partial component * chore: update fallback CMS partials API endpoint * feat: update blog link to netlify * feat: add redirect for linked blog posts * chore: update blog links to relative links * feat: move blog url to env * feat: remove blog route * chore: update blog links * chore: remove old blog code * chore: update default blog url * feat: add netlify partials css
- Loading branch information
1 parent
8a52b59
commit 0d004a4
Showing
42 changed files
with
107 additions
and
1,836 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { MDXRemote } from 'next-mdx-remote' | ||
import { useState, useEffect } from 'react' | ||
import Loading from './loading' | ||
|
||
/** | ||
* @typedef {Object} NetlifyPartialProps | ||
* @prop {string} [route] | ||
* @prop {string} [className] | ||
* @prop {JSX.Element} [fallback] | ||
*/ | ||
|
||
/** | ||
* | ||
* @param {NetlifyPartialProps} props | ||
* @returns {JSX.Element} | ||
*/ | ||
export default function NetlifyPartial({ route, className, fallback }) { | ||
/** @type [any, null | any] */ | ||
const [content, setContent] = useState() | ||
const [error, setError] = useState(false) | ||
useEffect(() => { | ||
// TODO: Update fallback when we have the blog in production. | ||
const host = | ||
process.env.NEXT_PUBLIC_NETLIFY_CMS_ENDPOINT || 'https://blog.nft.storage' | ||
fetch(`${host}/api/partials/${route}`) | ||
.then(async (response) => { | ||
return await response.text() | ||
}) | ||
.then((text) => { | ||
const obj = JSON.parse(text) | ||
setContent(obj.props.partial.content) | ||
}) | ||
.catch((e) => { | ||
setError(e) | ||
}) | ||
}, [route]) | ||
|
||
if (error) { | ||
if (fallback) { | ||
return <div className={className}>{fallback}</div> | ||
} | ||
return ( | ||
<div className={className}> | ||
<p>An unexpected error occured.</p> | ||
</div> | ||
) | ||
} | ||
|
||
if (!content) { | ||
return ( | ||
<div className={className}> | ||
<Loading /> | ||
</div> | ||
) | ||
} | ||
|
||
return ( | ||
content && ( | ||
<div className={className}> | ||
<MDXRemote {...content} /> | ||
</div> | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.