(Vitepress, Vuepress) + Utterances 댓글 기능 만들기 Vitepress, Vuepress 두 개다 가능합니다.
이 포스팅은 필자가 댓글 기능을 추가할 당시 vitepress는 없고 vuepress만 검색되어서 눈물을 머금고 쓰는 글입니다.
시작하기 앞서 간단히 설명하다면
Utterances는 GitHub Issue 기반으로 댓글을 작성할 수 있게 해줍니다.
장점
그냥 깃허브 블로그 Repository에 해도 상관은 없지만 필자의 경우는 블로그 Repository와 댓글을 따로 관리하기 위해 분할해서 만들었다.
아래 링크로 접속하여 설치하면 된다. 설치를 할 때 옵션이 두 개 있는데
모든 저장소에 올리거면 레포를 안 만들었지 Only Select Repositories를 통해, 댓글 Issue 가 올라올 저장소로 위에서 생성한 레포를 선택한 후 Install 하면 된다.
https://github.com/apps/utterances
GitHub: Let’s build from here
GitHub is where over 83 million developers shape the future of software, together. Contribute to the open source community, manage your Git repositories, review code like a pro, track bugs and feat...
github.com
.vitepress/components/Comment.vue // vitepress경우
.vuepress/components/Comment.vue // vuepress경우
해당 경로에 Comment.vue 파일을 생성한다.
<template>
<div ref="comment" style=" margin: 120px 0px 0px 0px;"></div>
</template>
<script>
export default {
mounted() {
const utterances = document.createElement("script");
utterances.type = "text/javascript";
utterances.async = true;
utterances.crossorigin = "anonymous";
utterances.src = "https://utteranc.es/client.js";
utterances.setAttribute("issue-term", "pathname"); // 1번
utterances.setAttribute("theme", "photon-dark");
utterances.setAttribute("repo", `아까 만들어둔 repo명 ex)kimjuneseo/blog_comment`); // 2번
this.$refs.comment.appendChild(utterances);
}
};
</script>
1. repo 위에서 선택한 래포를 적어준다.
ex) kimjuneseo/blog_comment.
2. Blog Post - Issue Mapping
이슈를 블로그의 어떤 페이지와 매핑을 시킬지 Key를 결정한다.
체크한 부분들을 입력해준다. 필자는 고유하고 수정을 하지 않을 것 같은 pathname을 선택했다.
import Comment from '../components/Comment.vue'
export default {
... // 생략
enhanceApp({ app }) {
app.component('Comment', Comment)
}
...
}
원하는 파일에서 <Comment />를 추가해주면 끝입니다!.
정상적으로 작동하시는 걸 보실 수 있습니다.! 아래링크로 들어가셔서 댓글 달아보세요.