Elffuss BraidHub

kikocis/lancedb public

docs: add permanent link chain icon to headings without impacting SEO (#1746)

I noted that there are no permanent links in the docs. Adapted the
current best solution from
https://github.com/squidfunk/mkdocs-material/discussions/3535. It adds a
GitHub-like chain icon to the left of each heading (right on mobile) and
does not impact SEO unlike the default solution with pilcrow char `¶`
that might show up on google search results.

<img alt="image"
src="https://user-images.githubusercontent.com/182589/153004627-6df3f8e9-c747-4f43-bd62-a8dabaa96c3f.gif">
Changesetaba9e2e83ce63bd368bfa7317c2b6acf23c071fea892564817358dae8d8151b7
AuthorDominik Weckmüller <47481567+do-me@users.noreply.github.com> · 2024-10-14 20:58 +02:00
CommitterGitHub <noreply@github.com> · 2024-10-14 11:58 -07:00
Parents16186d0dd1cf

Browse the files at this changeset

2 files changed

modified docs/mkdocs.yml +3 −0
@@ -90,6 +90,9 @@
9090 - pymdownx.emoji:
9191 emoji_index: !!python/name:material.extensions.emoji.twemoji
9292 emoji_generator: !!python/name:material.extensions.emoji.to_svg
93+ - markdown.extensions.toc:
94+ baselevel: 1
95+ permalink: ""
9396
9497 nav:
9598 - Home:
modified docs/src/styles/extra.css +43 −1
@@ -39,4 +39,46 @@
3939 height: 1.2rem;
4040 margin-top: -.1rem;
4141 }
42- }
No newline at the end of the file
42+ }
43+
44+/* remove pilcrow as permanent link and add chain icon similar to github https://github.com/squidfunk/mkdocs-material/discussions/3535 */
45+
46+.headerlink {
47+ --permalink-size: 16px; /* for font-relative sizes, 0.6em is a good choice */
48+ --permalink-spacing: 4px;
49+
50+ width: calc(var(--permalink-size) + var(--permalink-spacing));
51+ height: var(--permalink-size);
52+ vertical-align: middle;
53+ background-color: var(--md-default-fg-color--lighter);
54+ background-size: var(--permalink-size);
55+ mask-size: var(--permalink-size);
56+ -webkit-mask-size: var(--permalink-size);
57+ mask-repeat: no-repeat;
58+ -webkit-mask-repeat: no-repeat;
59+ visibility: visible;
60+ mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg>');
61+ -webkit-mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg>');
62+}
63+
64+[id]:target .headerlink {
65+ background-color: var(--md-typeset-a-color);
66+}
67+
68+.headerlink:hover {
69+ background-color: var(--md-accent-fg-color) !important;
70+}
71+
72+@media screen and (min-width: 76.25em) {
73+ h1, h2, h3, h4, h5, h6 {
74+ display: flex;
75+ align-items: center;
76+ flex-direction: row;
77+ column-gap: 0.2em; /* fixes spaces in titles */
78+ }
79+
80+ .headerlink {
81+ order: -1;
82+ margin-left: calc(var(--permalink-size) * -1 - var(--permalink-spacing)) !important;
83+ }
84+}