Showing only excerpts (selectively) for not logged in users

AI 生成的摘要

ewanly proposes a native Discourse feature allowing topic authors to selectively show excerpts to non-logged-in users while hiding the rest of the content, aiming to increase registration rates. The suggestion involves using a custom HTML-like tag (e.g., <excerpt>) within topic content to define visible text, with the remainder revealed only after login. simon responds that a similar effect can be achieved currently by wrapping text in <span class="excerpt"> and implementing a site customization script to replace the full content with the excerpt and a “login to continue” prompt for anonymous users. ewanly acknowledges the workaround but finds it too complex for average users, reiterating that a built-in, user-friendly feature would be more effective for encouraging sign-ups and is likely to be widely adopted if implemented.

What if we have the ability to show only excerpts for not logged in users in a chosen topics. But this excerpt position and length are defined when needed by the author of the topic.

This could be defined into any topic content (without the need to do any general setup) by placing a special code (just like HTML code special to Discourse).

The code could be any thing like:
<x> shown text </x> hidden text.
or
<x-start> shown text <x-end> hidden text.
or
<excerpt> shown text </excerpt> hidden text.


Example:

<excerpt> Here is a text seen by anyone " whom allowed in the related category security setup default" </excerpt> and here is the rest of the topic’s text which shown only to the logged in users “which is also considering the related cat security”.


So Everyone see only excerpted area with ( … login to continue) added:
Here is a text seen by anyone " whom allowed in the related category security setup default"… (login to continue)

Logged-in users see all topic content:
Here is a text seen by anyone " whom allowed in the related category security setup default" and here is the rest of the topic’s text which shown only to the logged in users “which is also considering the related cat security”.


The main idea is to improve the rate of registered/logged in users and to be able to bring them back more frequently by the summary emails.

The usage of this feature could be selected only on some topics which the author/moderator believe that the user would need to see the rest, so he would register.

1 个赞

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 个赞

Thank you @simon but it’s sound a bit complicated even for me :slight_smile:

I think this request would be easy to do as a standard Discourse feature (with little time, but sure for an expert touch) in case found useful to every body. And I hope it would be so.

I believe it would be useful and used by many. It’s provide the ability for a gentle push to increase registered users.

1 个赞