@@ -50,47 +50,55 @@ const fKeys = config.post.frontmatterKeys
5050 }
5151</div >
5252
53- <article class =" displaying-table-of-contents mx-auto prose dark:prose-invert" >
53+ <article class =" component-article-detail__article displaying-table-of-contents mx-auto prose dark:prose-invert" >
5454 <slot />
5555</article >
5656
5757<script is:inline type =" module" define:vars ={ { entry , config }} >
58+ import { withViewTransition } from 'https://esm.sh/astro-view-transition-script@latest'
59+ import rehypeParse from 'https://esm.sh/rehype-parse@9?bundle'
60+ import rehypeRemark from 'https://esm.sh/rehype-remark@10?bundle'
61+ import remarkGfm from 'https://esm.sh/remark-gfm@4?bundle'
62+ import remarkStringify from 'https://esm.sh/remark-stringify@11?bundle'
5863import { unified } from 'https://esm.sh/unified@11?bundle'
5964import { stringify } from 'https://esm.sh/yaml@2?bundle&exports=stringify'
60- import rehypeParse from 'rehype-parse'
61- import rehypeRemark from 'rehype-remark'
62- import remarkGfm from 'remark-gfm'
63- import remarkStringify from 'remark-stringify'
6465
65- const md = config.post.export.md
66+ function task(state) {
67+ const md = config.post.export.md
6668
67- if (md) {
68- const article = document.querySelector('article')
69- const btnExport2Md = document.querySelector('.btn-export-to-md')
70- btnExport2Md.addEventListener('click', async () => {
69+ if (md) {
70+ const article = state.document.querySelector('.component-article-detail__article')
7171 if (!article)
7272 return
7373
74- const html = article.innerHTML
75-
76- const file = await unified()
77- .use(rehypeParse, md.rehypeParse)
78- .use(rehypeRemark, md.rehypeRemark)
79- .use(remarkGfm, md.remarkGfm)
80- .use(remarkStringify, md.remarkStringify)
81- .process(html)
82-
83- const frontmatter = stringify(entry.data)
84-
85- const blob = new Blob([`---\n${frontmatter}---\n\n${file.toString()}`], { type: 'text/markdown' })
86- const url = URL.createObjectURL(blob)
87- const a = document.createElement('a')
88- a.href = url
89- a.download = `${entry.id}.md`
90- document.body.appendChild(a)
91- a.click()
92- document.body.removeChild(a)
93- URL.revokeObjectURL(url)
94- })
74+ const btnExport2Md = state.document.querySelector('.btn-export-to-md')
75+ btnExport2Md.addEventListener('click', async () => {
76+ const html = article.innerHTML
77+
78+ const file = await unified()
79+ .use(rehypeParse, md.rehypeParse)
80+ .use(rehypeRemark, md.rehypeRemark)
81+ .use(remarkGfm, md.remarkGfm)
82+ .use(remarkStringify, md.remarkStringify)
83+ .process(html)
84+
85+ const frontmatter = stringify(entry.data)
86+
87+ const blob = new Blob([`---\n${frontmatter}---\n\n${file.toString()}`], { type: 'text/markdown' })
88+ const url = URL.createObjectURL(blob)
89+ const a = state.document.createElement('a')
90+ a.href = url
91+ a.download = `${entry.id}.md`
92+ state.document.body.appendChild(a)
93+ a.click()
94+ state.document.body.removeChild(a)
95+ URL.revokeObjectURL(url)
96+ })
97+ }
9598}
99+
100+ withViewTransition({
101+ initial: task,
102+ done: task,
103+ })
96104</script >
0 commit comments