# 공개 게시물에 비공개 콘텐츠가 있나요?

**URL:** <https://meta.discourse.org/t/private-content-in-public-post/267266>\
**Category:** Feature\
**Created:** [6월 5, 2023, 3:28오후 UTC](https://meta.discourse.org/t/private-content-in-public-post/267266 "2023-06-05T15:28:24Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Lhc\_fl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lhc_fl/32/268115_2.png) [@Lhc\_fl](https://meta.discourse.org/u/Lhc_fl)\
**Post date:** [6월 6, 2023, 2:43오전 UTC](https://meta.discourse.org/t/private-content-in-public-post/267266/5 "2023-06-06T02:43:38Z")

</div>

로그인하지 않은 사용자가 프론트 엔드에서 게시물을 숨길 수 있는 테마 컴포넌트를 개발했습니다. 물론, 풍부한 개발 경험을 가진 사용자라면 백엔드에서 직접 쉽게 가져갈 수 있습니다.

아직 이 컴포넌트를 패키지로 묶지 않았으므로, 아래 코드를 그대로 사용해 주세요.

Head Tag:

```javascript
<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

```css
.anon .lycoris-hiddened {
    display: none;

    .post-info.edits {
        display: none;
    
    }
}

```

---

_[View the full topic](https://meta.discourse.org/t/private-content-in-public-post/267266)._
