-
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support useUtterances dark theme
- Loading branch information
Showing
3 changed files
with
52 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { useAppStore } from 'valaxy' | ||
import { onMounted, ref, watch } from 'vue' | ||
|
||
/** | ||
* @see https://utteranc.es/ | ||
*/ | ||
export function useUtterances() { | ||
const app = useAppStore() | ||
|
||
const utterScriptRef = ref<HTMLScriptElement>() | ||
/** | ||
* mount utterances | ||
* @see https://utteranc.es/ | ||
*/ | ||
function createUtterancesScript() { | ||
utterScriptRef.value = document.createElement('script') | ||
|
||
utterScriptRef.value.src = 'https://utteranc.es/client.js' | ||
utterScriptRef.value.async = true | ||
utterScriptRef.value.crossOrigin = 'anonymous' | ||
|
||
utterScriptRef.value.setAttribute('repo', 'YunYouJun/valaxy') | ||
utterScriptRef.value.setAttribute('issue-term', 'pathname') | ||
utterScriptRef.value.setAttribute('label', 'utterances') | ||
|
||
utterScriptRef.value.setAttribute('theme', app.isDark ? 'github-dark' : 'github-light') | ||
|
||
const commentContainer = document.querySelector('.comment') | ||
|
||
if (commentContainer) { | ||
// 如果旧元素存在,移除旧元素 | ||
const utterancesContainer = commentContainer.querySelector('.utterances') | ||
if (utterancesContainer) | ||
commentContainer.removeChild(utterancesContainer) | ||
|
||
commentContainer.appendChild(utterScriptRef.value) | ||
} | ||
} | ||
|
||
// watch dark mode for theme | ||
watch(() => app.isDark, () => { | ||
createUtterancesScript() | ||
}) | ||
|
||
onMounted(() => { | ||
createUtterancesScript() | ||
}) | ||
} |
895e486
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://yun.valaxy.site as production
🚀 Deployed on https://67754ff04e3074a3dde33240--valaxy.netlify.app