Skip to content

Commit 91558a1

Browse files
committed
anchors available. scroll to not working.
1 parent 1d8eb51 commit 91558a1

File tree

4 files changed

+51
-12
lines changed

4 files changed

+51
-12
lines changed

markdown-it-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const markdownItSetup = async (md) => {
3838

3939
// https://github.com/valeriangalliat/markdown-it-anchor/tree/master
4040
md.use(mditPluginAnchor, {
41+
permalink: mditPluginAnchor.permalink.headerLink(),
4142
// https://github.com/valeriangalliat/markdown-it-anchor/tree/master?tab=readme-ov-file#link-after-header
4243
// permalink: mditPluginAnchor.permalink.linkAfterHeader({
4344
// style: "visually-hidden",

src/css/app.scss

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ body.body--light {
5353
--main-background: var(--mys-basics-50);
5454
--main-background-dots: hsla(198, 63%, 15%, 0.5);
5555
// --main-background-dots: var(--mys-blue-950);
56-
5756
}
5857

5958
body.body--dark {
@@ -85,7 +84,7 @@ body {
8584
}
8685

8786
a {
88-
color: var(--text-primary);
87+
color: var(--text-primary);
8988
}
9089

9190
body.body--light {
@@ -157,3 +156,12 @@ html {
157156
color: var(--text-primary);
158157
}
159158

159+
// headings
160+
.header-anchor {
161+
text-decoration: none;
162+
}
163+
164+
.header-anchor:hover {
165+
-webkit-text-decoration: underline;
166+
text-decoration: underline;
167+
}

src/pages/MKS_Part_Details.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const coverImage = `../${part.path_base}/${part.meta.coverImage}`
7272
padding: 1em
7373
.back
7474
display: block
75-
margin-left: 3em
75+
// margin-left: 3em
7676
cursor: pointer
7777
header
7878
display: flex

src/router/index.js

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { route } from "quasar/wrappers";
1+
import { route } from 'quasar/wrappers'
2+
// import { nextTick } from 'vue'
23
import {
34
createRouter,
45
createMemoryHistory,
56
createWebHistory,
67
createWebHashHistory,
7-
} from "vue-router";
8-
import routes from "./routes";
8+
} from 'vue-router'
9+
import routes from './routes'
910

1011
/*
1112
* If not building with SSR mode, you can
@@ -19,16 +20,27 @@ import routes from "./routes";
1920
export default route(function (/* { store, ssrContext } */) {
2021
const createHistory = process.env.SERVER
2122
? createMemoryHistory
22-
: process.env.VUE_ROUTER_MODE === "history"
23-
? createWebHistory
24-
: createWebHashHistory;
23+
: process.env.VUE_ROUTER_MODE === 'history'
24+
? createWebHistory
25+
: createWebHashHistory
2526

2627
const Router = createRouter({
2728
// scrollBehavior: () => ({ left: 0, top: 0 }),
2829
// https://router.vuejs.org/guide/advanced/scroll-behavior.html#Scroll-Behavior
2930
// scrollBehavior(to, from, savedPosition) {
30-
scrollBehavior(to,) {
31+
scrollBehavior(to) {
3132
if (to.hash) {
33+
// https://router.vuejs.org/guide/advanced/scroll-behavior.html#Delaying-the-scroll
34+
// return new Promise((resolve) => {
35+
// setTimeout(() => {
36+
// resolve({
37+
// el: to.hash,
38+
// behavior: 'smooth',
39+
// })
40+
// }, 500)
41+
// })
42+
// this does not really work.
43+
// seems the md content is not rendered fast enough...
3244
return {
3345
el: to.hash,
3446
behavior: 'smooth',
@@ -43,5 +55,23 @@ export default route(function (/* { store, ssrContext } */) {
4355
history: createHistory(process.env.VUE_ROUTER_BASE),
4456
})
4557

46-
return Router;
47-
});
58+
// https://stackoverflow.com/questions/62409643/scroll-to-anchor-on-refresh-or-on-manual-url-change?noredirect=1&lq=1
59+
// Router.afterEach((to, from) => {
60+
// if (to.hash && to.path != from.path) {
61+
// // Vue.nextTick().then(() => VueScrollTo.scrollTo(to.hash, 700))
62+
// nextTick().then(() => {
63+
// setTimeout(() => {
64+
// // console.log(`to.hash.replace('#', '')`, to.hash.replace('#', ''))
65+
// const target = document.getElementById(to.hash.replace("#", ''))
66+
// // console.log('target', target)
67+
// // https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
68+
// target.scrollIntoView({
69+
// behavior: 'smooth',
70+
// })
71+
// }, 200);
72+
// })
73+
// }
74+
// })
75+
76+
return Router
77+
})

0 commit comments

Comments
 (0)