Skip to content

Commit 8541331

Browse files
committed
links page dark mode, github markdown works
1 parent 7cb8a09 commit 8541331

File tree

7 files changed

+1407
-9
lines changed

7 files changed

+1407
-9
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
import { Markdown } from 'astro-remote';
3+
4+
import List from '@/layouts/List.astro';
5+
import { BOOKMARKS } from '@/constants/data';
6+
import { getPageMetadata } from '@/utils/metadata';
7+
8+
const { README_RAW_URL, REPO } = BOOKMARKS;
9+
10+
const readmeContent = await fetch(README_RAW_URL).then((response) => response.text());
11+
12+
const metadata = getPageMetadata('lists/links');
13+
14+
// not generating id="..." links href="#..."
15+
---
16+
17+
<List {metadata}>
18+
<div class="markdown-body">
19+
<p>
20+
My personal bookmarks collection which is hosted in this repo: <a href={REPO} target="_blank"
21+
>{REPO}</a
22+
>
23+
</p>
24+
25+
<Markdown content={readmeContent} sanitize={{ dropElements: ['h1'] }} />
26+
</div>
27+
</List>
28+
29+
<style is:global>
30+
.markdown-body {
31+
/* set transparent bg-color */
32+
@apply !bg-transparent;
33+
34+
/* fix list style */
35+
ul,
36+
ol {
37+
list-style: revert;
38+
}
39+
}
40+
</style>
41+
42+
<script>
43+
import { THEME_CONFIG } from '@/constants/themes';
44+
import { getCurrentMode } from '@/utils/dom';
45+
import { removeTrailingSlash } from '@/utils/paths';
46+
47+
import type { ChangeThemeCustomEvent } from '@/types/constants';
48+
49+
const { CHANGE_EVENT } = THEME_CONFIG;
50+
51+
const loadStylesheet = (href: string) => {
52+
const existingLink = document.querySelector('link[data-theme="dynamic"]');
53+
if (existingLink) existingLink.remove();
54+
55+
const trimmedHref = removeTrailingSlash(href);
56+
57+
const link = document.createElement('link');
58+
link.rel = 'stylesheet';
59+
link.href = trimmedHref;
60+
link.dataset.theme = 'dynamic';
61+
document.head.appendChild(link);
62+
};
63+
64+
const loadGithubTheme = (mode: 'dark' | 'light') => {
65+
if (mode === 'dark') {
66+
// loadStylesheet('node_modules/github-markdown-css/github-markdown-dark.css');
67+
import('github-markdown-css/github-markdown-dark.css');
68+
} else {
69+
import('github-markdown-css/github-markdown-light.css');
70+
// loadStylesheet('node_modules/github-markdown-css/github-markdown-light.css');
71+
}
72+
};
73+
74+
// will run only on page load
75+
const mode = getCurrentMode();
76+
loadGithubTheme(mode);
77+
78+
// will run on button click
79+
document.addEventListener(CHANGE_EVENT, async (event) => {
80+
const customEvent = event as ChangeThemeCustomEvent;
81+
const { mode } = customEvent.detail.theme;
82+
83+
loadGithubTheme(mode);
84+
});
85+
</script>

docs/working-notes/todo3.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,5 +495,8 @@ ovo radi
495495
remote markdown
496496
not generating id="..." links href="#..."
497497
custom my-prose-links
498+
499+
// dark theme for github markdown
500+
https://github.com/sindresorhus/github-markdown-css/issues/104
498501
------------
499502
```

0 commit comments

Comments
 (0)