게시글 안쪽의 콘텐츠만 로그인한 사용자에게만 표시할 수 있는 방법이 있을까요?
제가 생각하는 사용 사례는 가상 이벤트 게시입니다. 우리 커뮤니티에는 가상으로 모이는 워킹 그룹이 정말 많습니다. 우리는 일반 방문객들에게 그룹과 모임의 존재 및 일정을 알리고 싶지만, 줌 링크를 공개적으로 게시하고 싶지는 않습니다.
게시글 안쪽의 콘텐츠만 로그인한 사용자에게만 표시할 수 있는 방법이 있을까요?
제가 생각하는 사용 사례는 가상 이벤트 게시입니다. 우리 커뮤니티에는 가상으로 모이는 워킹 그룹이 정말 많습니다. 우리는 일반 방문객들에게 그룹과 모임의 존재 및 일정을 알리고 싶지만, 줌 링크를 공개적으로 게시하고 싶지는 않습니다.
Marty, 안녕하세요!
Whispers가 실제로 그런 동작을 합니다: Creating a whisper post
whisper 게시물은 게시된 후에는 “unwhisper”(공개 전환)할 수 없지만, 이 테마 컴포넌트를 사용하면 가능합니다: Toggle Whisper 👁
감사합니다. 거의 원하는 형태네요. 이상적인 방식은 게시물 내에서 콘텐츠를 포맷팅하여, 로그인하지 않은 사용자에게는 "로그인한 사용자만 링크를 볼 수 있습니다"라는 메시지가 표시되고, 나머지 게시물 내용은 모두에게 보이도록 하는 것입니다. 하지만 지금은 위스퍼(비밀메시지) 기능이 잘 작동할 것 같습니다.
아직 초보 관리자라 모든 기능을 익히는 중입니다.
디스코urs 수정에 대해 잘 알지는 못하지만, 그건 조금 까다로워 보이며, 클라이언트 측 코드를 조정하는 방법을 아는 사람이 우회하지 못하게 하려면 플러그인이 필요할 것입니다.
로그인하지 않은 사용자가 프론트 엔드에서 게시물을 숨길 수 있는 테마 컴포넌트를 개발했습니다. 물론, 풍부한 개발 경험을 가진 사용자라면 백엔드에서 직접 쉽게 가져갈 수 있습니다.
아직 이 컴포넌트를 패키지로 묶지 않았으므로, 아래 코드를 그대로 사용해 주세요.
Head Tag:
<script type="text/discourse-plugin" version="1.6.0">
const user = api.getCurrentUser();
const I18n = require("I18n");
const pid = "post_hider"
const tl4_css = `
.d-editor-preview [data-theme-hide] {
background: var(--tertiary);
color: var(--secondary);
border-top: 2px solid var(--secondary);
position: sticky;
top: 0;
height: 30px;
display: flex;
align-items: center;
justify-content: center;
}
.d-editor-preview [data-theme-hide]::before {
content: "This post is hidden";
}
`
api.addPostClassesCallback((attrs) => {
if (attrs?.cooked?.includes(`<div data-theme-hide="true">`)) {
return ["lycoris-hiddened"];
} else {
return [];
}
});
if (!user) {
api.decorateCookedElement((el, helper) => {
function hide_post() {
setTimeout( () => {
try {
document.querySelector(`[data-post-id="${helper?.widget?.attrs?.id}"]`)?.parentElement?.remove();
} catch (err) {
console.log(el);
console.log(err);
}
}, 1000);
}
if (el?.querySelector(`[data-theme-hide="true"]`)) {
el.innerHTML = `<p>This post is hidden</p>`;
hide_post();
}
}, {
id: pid,
afterAdopt: true,
onlyStream: true,
});
} else if (user?.trust_level == 4) {
const s = document.createElement("style");
s.innerHTML = tl4_css;
document.body.appendChild(s);
api.decorateCookedElement((el, helper) => {
if (el?.querySelector(`[data-theme-hide="true"]`)) {
el.innerHTML = `<div class="d-wrap" data-wrap="tips" data-type="warn"><p>帖子被设置为对社区未登录用户隐藏</p></div> ` + el.innerHTML;
}
}, {
id: pid,
afterAdopt: true,
onlyStream: true,
});
if (!I18n.translations[I18n.currentLocale()].js.composer) {
I18n.translations[I18n.currentLocale()].js.composer = {};
}
I18n.translations[I18n.currentLocale()].js.composer.hide_text = " ";
I18n.translations[I18n.currentLocale()].js.composer.make_hide = "Hide this post";
api.modifyClass("controller:composer", {
pluginId: pid,
actions: {
insertHide() {
this.get("toolbarEvent").applySurround(
`<div data-theme-hide="true">`,
`</div>\n`,
"hide_text"
);
},
},
});
api.addToolbarPopupMenuOptionsCallback(() => {
return {
action: "insertHide",
icon: "far-eye-slash",
label: "composer.make_hide",
};
});
}
</script>
CSS
.anon .lycoris-hiddened {
display: none;
.post-info.edits {
display: none;
}
}