Update site

- Fix the mislinked images
- Add a table of contents
This commit is contained in:
Gabriel Arazas 2021-07-10 22:21:24 +08:00
parent 92a8179dd0
commit 4c418aa679
5 changed files with 37 additions and 3 deletions

View File

@ -0,0 +1,11 @@
import React from 'react';
import config from '../../next.config.js';
const MyImage = ({ src, width, height, ...props }) => {
const _src = `${config.basePath}${src}`
return (
<img src={_src} placeholder="blur"/>
);
};
export default MyImage;

View File

@ -1,19 +1,25 @@
import React from 'react';
import unified from 'unified';
import orgParse from 'uniorg-parse';
import org2rehype from 'uniorg-rehype';
import rehype2react from 'rehype-react';
import toc from '@jsdevtools/rehype-toc';
import Link from './Link';
import Image from './Image';
// we use rehype-react to process hast and transform it to React
// component, which allows as replacing some of components with custom
// implementation. e.g., we can replace all <a> links to use
// `next/link`.
const processor = unified().use(rehype2react, {
const processor = unified()
.use(rehype2react, {
createElement: React.createElement,
Fragment: React.Fragment,
components: {
a: Link,
img: Image,
},
});

View File

@ -1,4 +1,5 @@
import * as path from 'path';
import toc from '@jsdevtools/rehype-toc';
import trough from 'trough';
import toVFile from 'to-vfile';
import findDown from 'vfile-find-down';
@ -73,6 +74,7 @@ function populateBacklinks(files) {
backlinks[file.data.slug] || new Set();
file.data.links.forEach((other) => {
if (other === file.data.slug) { return; }
backlinks[other] = backlinks[other] || new Set();
backlinks[other].add(file.data.slug);
});

View File

@ -5,6 +5,7 @@ import org2rehype from 'uniorg-rehype';
import extractKeywords from 'uniorg-extract-keywords';
import { uniorgSlug } from 'uniorg-slug';
import { visitIds } from 'orgast-util-visit-ids';
import toc from '@jsdevtools/rehype-toc'
const processor = unified()
.use(orgParse)
@ -12,6 +13,7 @@ const processor = unified()
.use(uniorgSlug)
.use(extractIds)
.use(org2rehype)
.use(toc)
.use(toJson);
export default async function orgToHtml(file) {

View File

@ -1,6 +1,5 @@
html,
body {
padding: 0;
body { padding: 0;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
@ -32,3 +31,17 @@ code {
background-color: #eee;
}
ol {
counter-reset: item;
list-style: none;
}
ol>li {
counter-increment: item;
}
ol>li::before {
content: counters(item, '.') '. ';
}
img {
max-width: 100%;
}