Showing only excerpts (selectively) for not logged in users

The ‘excerpt’ class is whitelisted for the span tag, so you could try wrapping the excerpt in <span class="excerpt"></span> tags and then add a site customization to display only the excerpt for non-logged in users.

This works, but I’m not sure if it will have any unintended side effects:

<script type="text/discourse-plugin" version="0.5">
      
    const anonExcerpt = ($elem) => {
        const currentUser = api.getCurrentUser();
        const excerpt = $elem.find('.excerpt').html();
        
        if(!currentUser) {
            $elem.html(excerpt + ' <strong style="white-space:nowrap;">( ...login to continue)</strong>');
        }
    }
    
    api.decorateCooked(anonExcerpt);
</script>
4 个赞