카테고리별로 특정 주제와 게시물의 리액션을 다르게 설정할 수 있을까요?
기본 제공 기능에서 관련 사항을 찾지 못했고, 기존 컴포넌트도 없는 것 같습니다.
현재 이것이 불가능하다면, 이와 유사한 기능을 구현하기 위해 어떤 단계가 필요할까요?
카테고리별로 특정 주제와 게시물의 리액션을 다르게 설정할 수 있을까요?
기본 제공 기능에서 관련 사항을 찾지 못했고, 기존 컴포넌트도 없는 것 같습니다.
현재 이것이 불가능하다면, 이와 유사한 기능을 구현하기 위해 어떤 단계가 필요할까요?
완벽합니다 ![]()
다른 환경에서 개발 업무를 해본 경험이 있지만, 테마 컴포넌트를 통해 이것이 가능한지 탐구해 보고 있습니다.
AI의 작은 도움 덕분에
작동하는 것 같지만, 이것이 Discourse에서 올바르게 구현하는 방식인지 100% 확신은 없습니다:
<script type="text/discourse-plugin" version="0.1">
api.onPageChange(() => {
try {
const isTopicPage = /^\/t\//.test(window.location.pathname);
// Only run on topic pages
if (!isTopicPage) return;
const allowedCategories = ['ask-a-question']; // Use category slugs directly
// Access the topic details to get the category slug
const topic = Discourse.__container__.lookup("controller:topic");
const categorySlug = topic && topic.get("model.category.slug");
const isAllowedCategory = categorySlug && allowedCategories.includes(categorySlug);
// Function to hide or show the specific emoji
const toggleReactionEmoji = () => {
const emoji = document.querySelector("[data-reaction='frog']");
if (emoji) {
emoji.style.display = isAllowedCategory ? '' : 'none';
console.log(`Emoji with data-reaction='frog' ${isAllowedCategory ? 'shown' : 'hidden'}.`);
}
};
// Initial check in case the element is already in the DOM
toggleReactionEmoji();
// Set up a mutation observer to hide/show emoji based on category changes
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
mutation.addedNodes.forEach(node => {
if (node.nodeType === 1) { // Check if it's an element node
const emoji = node.querySelector("[data-reaction='frog']");
if (emoji) {
emoji.style.display = isAllowedCategory ? '' : 'none';
console.log(`Emoji with data-reaction='frog' found in mutation and ${isAllowedCategory ? 'shown' : 'hidden'}.`);
}
}
});
});
});
// Observe the body for child list changes (e.g., reactions being added)
observer.observe(document.body, { childList: true, subtree: true });
// Clean up the observer when navigating away
api.cleanupStream(() => observer.disconnect());
} catch (error) {
console.error("An error occurred in the emoji toggle script:", error);
}
});
</script>
어떤 식으로 진행되었는지 알 수 있을까요? 문서(docs)와 같은 특정 카테고리에 적용하고 싶은데, 메인 동기부여(메인 모티베이션)는 반응/칭찬(리액션/치어) 없이 이루어져야 합니다.