mirror of
https://github.com/alrayyes/wiki.git
synced 2025-05-11 03:04:21 +00:00
heading linking
This commit is contained in:
parent
04eeb2d10c
commit
fcd81353f8
7 changed files with 104 additions and 11 deletions
|
@ -26,7 +26,6 @@ export default function({ title, description, slug, externalResources }: HeadPro
|
|||
<link rel="icon" href={iconPath} />
|
||||
<meta name="description" content={description} />
|
||||
<meta name="generator" content="Quartz" />
|
||||
<base href={slug} />
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" />
|
||||
<link rel="stylesheet" type="text/css" href={stylePath} />
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
import path from 'path'
|
||||
import SlugAnchor from 'github-slugger'
|
||||
|
||||
const slugAnchor = new SlugAnchor()
|
||||
|
||||
function slugSegment(s: string): string {
|
||||
return s.replace(/\s/g, '-')
|
||||
|
@ -6,7 +9,7 @@ function slugSegment(s: string): string {
|
|||
|
||||
export function slugify(s: string): string {
|
||||
const [fp, anchor] = s.split("#", 2)
|
||||
const sluggedAnchor = anchor === undefined ? "" : "#" + slugSegment(anchor)
|
||||
const sluggedAnchor = anchor === undefined ? "" : "#" + slugAnchor.slug(anchor)
|
||||
const withoutFileExt = fp.replace(new RegExp(path.extname(fp) + '$'), '')
|
||||
const rawSlugSegments = withoutFileExt.split(path.sep)
|
||||
const slugParts: string = rawSlugSegments
|
||||
|
|
|
@ -2,13 +2,17 @@ import { PluggableList } from "unified"
|
|||
import remarkGfm from "remark-gfm"
|
||||
import smartypants from 'remark-smartypants'
|
||||
import { QuartzTransformerPlugin } from "../types"
|
||||
import rehypeSlug from "rehype-slug"
|
||||
import rehypeAutolinkHeadings from "rehype-autolink-headings/lib"
|
||||
|
||||
export interface Options {
|
||||
enableSmartyPants: boolean
|
||||
linkHeadings: boolean
|
||||
}
|
||||
|
||||
const defaultOptions: Options = {
|
||||
enableSmartyPants: true
|
||||
enableSmartyPants: true,
|
||||
linkHeadings: true
|
||||
}
|
||||
|
||||
export class GitHubFlavoredMarkdown extends QuartzTransformerPlugin {
|
||||
|
@ -25,6 +29,13 @@ export class GitHubFlavoredMarkdown extends QuartzTransformerPlugin {
|
|||
}
|
||||
|
||||
htmlPlugins(): PluggableList {
|
||||
return []
|
||||
return this.opts.linkHeadings
|
||||
? [rehypeSlug, [rehypeAutolinkHeadings, {
|
||||
behavior: 'append', content: {
|
||||
type: 'text',
|
||||
value: '§'
|
||||
}
|
||||
}]]
|
||||
: []
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,9 +42,9 @@ export class ObsidianFlavoredMarkdown extends QuartzTransformerPlugin {
|
|||
|
||||
} else {
|
||||
const [path, rawHeader, rawAlias] = capture
|
||||
const header = rawHeader?.slice(1).trim() ?? ""
|
||||
const anchor = rawHeader?.slice(1).trim() ?? ""
|
||||
const alias = rawAlias?.slice(1).trim() ?? path
|
||||
const url = slugify(path.trim() + header)
|
||||
const url = slugify(path.trim() + anchor)
|
||||
return {
|
||||
type: 'link',
|
||||
url,
|
||||
|
|
|
@ -85,12 +85,24 @@ thead {
|
|||
font-weight: revert;
|
||||
margin: 2rem 0 0;
|
||||
|
||||
&:hover > .hanchor {
|
||||
color: var(--secondary);
|
||||
}
|
||||
|
||||
article > & > a {
|
||||
color: var(--dark)
|
||||
color: var(--dark);
|
||||
&.internal {
|
||||
background-color: transparent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
&[id] > a {
|
||||
margin: 0 0.5rem;
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s ease;
|
||||
font-family: var(--codeFont);
|
||||
user-select: none;
|
||||
}
|
||||
&[id]:hover > a {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue