Skip to content

Commit

Permalink
Add rehype-slug and rehype-autolink-headings
Browse files Browse the repository at this point in the history
  • Loading branch information
laymonage committed Jan 1, 2025
1 parent 08618e3 commit 327b208
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
23 changes: 23 additions & 0 deletions astro.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import icon from 'astro-icon';

import pagefind from 'astro-pagefind';

import rehypeSlug from 'rehype-slug';

import rehypeAutolinkHeadings from 'rehype-autolink-headings';

import { astroOgImagesGenerator } from 'og-images-generator/astro';

import { paths } from './og-images.config';
Expand Down Expand Up @@ -66,6 +70,25 @@ export default defineConfig({
defaultColor: false,
transformers: [copyButton()],
},
rehypePlugins: [
rehypeSlug,
[
rehypeAutolinkHeadings,
{
behavior: 'prepend',
content: {
type: 'text',
value: '#',
},
headingProperties: {
className: ['anchor'],
},
properties: {
className: ['anchor-link'],
},
},
],
],
},
vite: {
resolve: {
Expand Down
63 changes: 63 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"react": "^19.0.0",
"react-dom": "^19.0.0",
"reading-time": "^1.5.0",
"rehype-autolink-headings": "^7.1.0",
"rehype-slug": "^6.0.0",
"swr": "^2.3.0",
"tailwindcss": "^3.4.17",
"typescript": "^5.7.2"
Expand Down
4 changes: 4 additions & 0 deletions src/styles/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ a,
@apply text-blue-800 hover:text-blue-700 focus:text-blue-700 dark:text-blue-300 dark:hover:text-blue-200 dark:focus:text-blue-200;
}

.anchor-link {
@apply -ml-6 w-6 inline-block no-underline;
}

[id] {
scroll-margin-top: 6rem;
}
Expand Down

0 comments on commit 327b208

Please sign in to comment.