mirror of
https://github.com/LukeHagar/unicorn-utterances.git
synced 2025-12-06 04:21:55 +00:00
Initial work to replace MDX with home-built
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -32,3 +32,5 @@ yarn-error.log*
|
|||||||
|
|
||||||
# vercel
|
# vercel
|
||||||
.vercel
|
.vercel
|
||||||
|
|
||||||
|
/public/posts
|
||||||
|
|||||||
1
@types/remark-html.d.ts
vendored
1
@types/remark-html.d.ts
vendored
@@ -1 +0,0 @@
|
|||||||
declare module 'remark-html'
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
export const EXAMPLE_PATH = 'blog-starter-typescript'
|
|
||||||
export const CMS_NAME = 'Markdown'
|
|
||||||
export const HOME_OG_IMAGE_URL =
|
|
||||||
'https://og-image.vercel.app/Next.js%20Blog%20Starter%20Example.png?theme=light&md=1&fontSize=100px&images=https%3A%2F%2Fassets.vercel.com%2Fimage%2Fupload%2Ffront%2Fassets%2Fdesign%2Fnextjs-black-logo.svg'
|
|
||||||
19
next.config.js
Normal file
19
next.config.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
const path = require('path');
|
||||||
|
const CopyPlugin = require("copy-webpack-plugin");
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
webpack: config => {
|
||||||
|
config.plugins.push(
|
||||||
|
new CopyPlugin({
|
||||||
|
patterns: [
|
||||||
|
{
|
||||||
|
from: path.resolve(__dirname, "content/blog"),
|
||||||
|
to: path.resolve(__dirname, 'public/posts')
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
||||||
1485
package-lock.json
generated
1485
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -8,11 +8,13 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"classnames": "2.3.1",
|
"classnames": "2.3.1",
|
||||||
|
"copy-webpack-plugin": "^9.0.1",
|
||||||
"date-fns": "2.21.3",
|
"date-fns": "2.21.3",
|
||||||
"gray-matter": "4.0.3",
|
"gray-matter": "4.0.3",
|
||||||
"next": "latest",
|
"next": "latest",
|
||||||
"react": "^17.0.2",
|
"react": "^17.0.2",
|
||||||
"react-dom": "^17.0.2",
|
"react-dom": "^17.0.2",
|
||||||
|
"rehype-img-size": "^0.0.1",
|
||||||
"rehype-parse": "^8.0.3",
|
"rehype-parse": "^8.0.3",
|
||||||
"rehype-react": "^7.0.3",
|
"rehype-react": "^7.0.3",
|
||||||
"rehype-stringify": "^9.0.2",
|
"rehype-stringify": "^9.0.2",
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 6.0 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 7.0 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 6.0 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 115 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 103 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 43 KiB |
1
src/api/index.ts
Normal file
1
src/api/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from './api';
|
||||||
@@ -13,13 +13,13 @@ interface useMarkdownRendererProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getComponents = ({
|
const getComponents = ({
|
||||||
postsDirectory,
|
|
||||||
slug
|
slug
|
||||||
}: useMarkdownRendererProps) => ({
|
}: useMarkdownRendererProps) => ({
|
||||||
img: (imgProps: unknown) => {
|
img: (imgProps: unknown) => {
|
||||||
const {src, ...props2} = imgProps as ImageProps;
|
const {src, ...props2} = imgProps as ImageProps;
|
||||||
const imagePath = join(postsDirectory, slug, src as string);
|
const imagePath = join('/posts', slug, src as string);
|
||||||
const beResponsive = props2.height && props2.width;
|
const beResponsive = !!(props2.height && props2.width);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Image
|
<Image
|
||||||
src={imagePath}
|
src={imagePath}
|
||||||
@@ -1,12 +1,15 @@
|
|||||||
import {getAllPosts} from '../lib/api'
|
import {getAllPosts} from '../api/api'
|
||||||
import Post from '../types/post'
|
import Post from '../types/post'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
import consts from '../utils/constants';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
allPosts: Post[]
|
allPosts: Post[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const Index = ({allPosts}: Props) => {
|
const Index = ({allPosts}: Props) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -15,7 +18,7 @@ const Index = ({allPosts}: Props) => {
|
|||||||
post =>
|
post =>
|
||||||
<li key={post.slug}>
|
<li key={post.slug}>
|
||||||
<h2>
|
<h2>
|
||||||
<Link href="/posts/[slug]" as={`/posts/${post.slug}`}>
|
<Link href={`/posts/[slug]`} as={`/posts/${post.slug}`}>
|
||||||
<a>{post.title}</a>
|
<a>{post.title}</a>
|
||||||
</Link>
|
</Link>
|
||||||
</h2>
|
</h2>
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
// import { useRouter } from 'next/router'
|
// import { useRouter } from 'next/router'
|
||||||
// import ErrorPage from 'next/error'
|
// import ErrorPage from 'next/error'
|
||||||
import {getPostBySlug, getAllPosts, postsDirectory} from '../../lib/api'
|
import {getPostBySlug, getAllPosts, postsDirectory} from '../../api/api'
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
import markdownToHtml from "../../lib/markdownToHtml";
|
import markdownToHtml from "../../utils/markdownToHtml";
|
||||||
import {useMarkdownRenderer} from "../../hooks/useMarkdownRenderer";
|
import {useMarkdownRenderer} from "../../hooks/useMarkdownRenderer";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -3,9 +3,13 @@ import remarkParse from "remark-parse";
|
|||||||
import remarkStringify from "remark-stringify";
|
import remarkStringify from "remark-stringify";
|
||||||
import remarkToRehype from 'remark-rehype';
|
import remarkToRehype from 'remark-rehype';
|
||||||
import rehypeStringify from "rehype-stringify";
|
import rehypeStringify from "rehype-stringify";
|
||||||
|
import path from "path";
|
||||||
|
import {postsDirectory} from "../api";
|
||||||
|
|
||||||
|
// Optional now. Probably should move to an array that's passed or something
|
||||||
// TODO: Create types
|
// TODO: Create types
|
||||||
const behead = require('remark-behead')
|
const behead = require('remark-behead')
|
||||||
|
const rehypeImageSize = require('rehype-img-size');
|
||||||
|
|
||||||
export default async function markdownToHtml(slug: string, markdown: string) {
|
export default async function markdownToHtml(slug: string, markdown: string) {
|
||||||
const result = await unified()
|
const result = await unified()
|
||||||
@@ -16,7 +20,10 @@ export default async function markdownToHtml(slug: string, markdown: string) {
|
|||||||
.use(remarkStringify)
|
.use(remarkStringify)
|
||||||
.use(remarkToRehype)
|
.use(remarkToRehype)
|
||||||
/* start rehype plugins here */
|
/* start rehype plugins here */
|
||||||
|
// TODO: https://github.com/ksoichiro/rehype-img-size/issues/4
|
||||||
|
.use(rehypeImageSize, {
|
||||||
|
dir: path.resolve(postsDirectory, slug),
|
||||||
|
})
|
||||||
/* end rehype plugins here */
|
/* end rehype plugins here */
|
||||||
.use(rehypeStringify)
|
.use(rehypeStringify)
|
||||||
.process(markdown);
|
.process(markdown);
|
||||||
Reference in New Issue
Block a user