This repository has been archived by the owner on Oct 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Initial working version with MDX remote #9
Open
zomars
wants to merge
10
commits into
yenly:main
Choose a base branch
from
zomars:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c5ad86b
Initial working version with MDX remote
zomars 9877705
Some wikilink fixes
zomars 494e464
Updates foam settings from upstream template
zomars 92620da
Paste images on public folder
zomars b442f2b
Fixes button import
zomars 2dfbc6e
Reworks remote mdx
zomars 2eeaf77
Re-Adds local md support
zomars 523cf06
Updates dependencies
zomars d560a2e
Fixes local example Link
zomars 73c51d6
Fixes footnote links
zomars File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"singleQuote": true, | ||
"semi": false | ||
} |
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
File renamed without changes.
File renamed without changes.
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,34 @@ | ||
# Foamy NextJS | ||
|
||
## Foam | ||
|
||
- [[readme]] | ||
- [[inbox]] | ||
- [[todo]] | ||
- For up-to-date tips, see [Foam Recipes](https://foambubble.github.io/foam/recipes) | ||
|
||
## NextJS | ||
|
||
- [Learn NextJS](https://nextjs.org/learn/basics/create-nextjs-app) | ||
- [NextJS Examples](https://github.com/vercel/next.js/tree/canary/examples) | ||
|
||
### Examples | ||
|
||
- [[syntax-highlighting]] | ||
- image in markdown [[excalidrawn]] | ||
- [[next-image-component-example]] | ||
- [[note]] in subfolder using remark footnotes | ||
- [[jsx-component-in-mdx-example]] | ||
- [[local-test]] | ||
|
||
[//begin]: # 'Autogenerated link references for markdown compatibility' | ||
[readme]: readme 'Foam' | ||
[inbox]: inbox 'Inbox' | ||
[todo]: todo 'Todo' | ||
[syntax-highlighting]: notes/syntax-highlighting 'Syntax Highlighting' | ||
[excalidrawn]: excalidrawn 'Excalidrawn' | ||
[next-image-component-example]: next-image-component-example 'Next Image Component Example' | ||
[note]: notes/note 'Note' | ||
[jsx-component-in-mdx-example]: jsx-component-in-mdx-example 'JSX Component in Mdx Example' | ||
[local-test]: local-test 'Local MDX Example' | ||
[//end]: # 'Autogenerated link references' |
3 changes: 0 additions & 3 deletions
3
pages/jsx-component-in-mdx-example.md → _posts/jsx-component-in-mdx-example.mdx
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 |
---|---|---|
@@ -1,9 +1,6 @@ | ||
import Button from '../components/button.js' | ||
|
||
# JSX Component in Mdx Example | ||
|
||
Look, a button! 👇 | ||
|
||
<Button>👋 Hello</Button> | ||
|
||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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,15 @@ | ||
import dynamic from 'next/dynamic' | ||
import AnchorTag from '../components/AnchorTag' | ||
import CodeBlock from '../components/CodeBlock' | ||
import Image from '../components/Image' | ||
|
||
// prettier-ignore | ||
const MDXComponents = { | ||
a: props => <AnchorTag {...props} />, | ||
code: CodeBlock, | ||
img: (props) => <div className="nextImageWrapper"><Image {...props} /></div>, | ||
Image: (props) => <div className="nextImageWrapper"><Image {...props} /></div>, | ||
Button: dynamic(() => import('../components/button')), | ||
} | ||
|
||
export default MDXComponents |
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,74 @@ | ||
import fs from 'fs' | ||
import matter from 'gray-matter' | ||
import renderToString from 'next-mdx-remote/render-to-string' | ||
import path from 'path' | ||
import MDXComponents from '../components/MDXComponents' | ||
import remarkPlugins from './remark' | ||
|
||
const root = process.cwd() | ||
const POSTS_DIR = '_posts' | ||
|
||
// POSTS_PATH is useful when you want to get the path to a specific file | ||
export const POSTS_PATH = path.join(root, POSTS_DIR) | ||
|
||
export const getAllFiles = function (dirPath, arrayOfFiles) { | ||
let files = fs.readdirSync(dirPath) | ||
|
||
arrayOfFiles = arrayOfFiles || [] | ||
|
||
files.forEach(function (file) { | ||
if (fs.statSync(`${dirPath}/${file}`).isDirectory()) { | ||
arrayOfFiles = getAllFiles(`${dirPath}/${file}`, arrayOfFiles) | ||
} else { | ||
arrayOfFiles.push( | ||
path.join(dirPath, '/', file).replace(`${POSTS_PATH}/`, '') | ||
) | ||
} | ||
}) | ||
|
||
return arrayOfFiles | ||
} | ||
|
||
// postFilePaths is the list of all mdx files inside the POSTS_PATH directory | ||
export const postFilePaths = getAllFiles(POSTS_PATH) | ||
// Only include md(x) files | ||
.filter((path) => /\.mdx?$/.test(path)) | ||
|
||
export async function getFileBySlug(slug) { | ||
const postFilePath = path.join(root, POSTS_DIR, `${slug}.mdx`) | ||
const source = fs.readFileSync(postFilePath, 'utf8') | ||
|
||
const { data, content } = matter(source) | ||
const mdxSource = await renderToString(content, { | ||
components: MDXComponents, | ||
mdxOptions: { | ||
remarkPlugins, | ||
}, | ||
scope: data, | ||
}) | ||
|
||
return { | ||
mdxSource, | ||
frontMatter: { | ||
slug: slug || null, | ||
...data, | ||
}, | ||
} | ||
} | ||
|
||
export async function getAllFilesFrontMatter() { | ||
const files = fs.readdirSync(path.join(root, POSTS_DIR)) | ||
|
||
return files.reduce((allPosts, postSlug) => { | ||
const source = fs.readFileSync(path.join(root, POSTS_DIR, postSlug), 'utf8') | ||
const { data } = matter(source) | ||
|
||
return [ | ||
{ | ||
...data, | ||
slug: postSlug.replace('.mdx', ''), | ||
}, | ||
...allPosts, | ||
] | ||
}, []) | ||
} |
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,23 @@ | ||
const remarkExternalLinks = require('remark-external-links') | ||
const remarkImages = require('remark-images') | ||
const remarkInlineLinks = require('remark-inline-links') | ||
const remarkFootnote = require('remark-numbered-footnote-labels') | ||
const remarkUnwrapImages = require('remark-unwrap-images') | ||
const remarkWikiLink = require('remark-wiki-link') | ||
|
||
const remarkPlugins = [ | ||
remarkImages, | ||
remarkExternalLinks, | ||
remarkFootnote, | ||
remarkInlineLinks, | ||
remarkUnwrapImages, | ||
[ | ||
remarkWikiLink, | ||
{ | ||
hrefTemplate: (permalink) => `${permalink}`, | ||
pageResolver: (name) => [name.replace(/ /g, '-').toLowerCase()], | ||
}, | ||
], | ||
] | ||
|
||
module.exports = remarkPlugins |
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 |
---|---|---|
@@ -1,19 +1,12 @@ | ||
const remarkImages = require('remark-images') | ||
const remarkExternalLinks = require('remark-external-links') | ||
const remarkFootnote = require('remark-numbered-footnote-labels') | ||
const remarkUnwrapImages = require('remark-unwrap-images') | ||
const remarkPlugins = require('./lib/remark') | ||
|
||
const withMDX = require('@next/mdx')({ | ||
extension: /\.mdx?$/, | ||
options: { | ||
remarkPlugins: [ | ||
remarkImages, | ||
remarkExternalLinks, | ||
remarkFootnote, | ||
remarkUnwrapImages | ||
] | ||
remarkPlugins, | ||
}, | ||
}) | ||
|
||
module.exports = withMDX({ | ||
pageExtensions: ['js', 'jsx', 'mdx', 'md'], | ||
}) |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this imported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nowhere yet... I've kept it in case of wanting a blog listing somewhere