Show "topic-excerpt" for all post on Latest Page


(Michael Woode) #1

I am looking for a way to show topic-excerpts for all post that are shown on the latest page (similar to the “topic-excerpt” shown for pinned posts) and not just titles as it currently is. I want to be able to let members have a peak of the post before they click on “read more” to view the full post. Anybody that has a hack on this should let me know.

Thanks.


Discourse 1.2 Extensibility Game Plan
Show excerpt for all topics via a theme
(Ajaz) #2

@sam I would also be interested to know how this may be possible. Also, for images to be fully displayed within the post instead of just an image name / link.

BTW: What are ‘featured’ topics? - how do these relate / differ to pinned posts ? … some of the code refers to ‘featured’ posts with a further reference to ‘excerpts’?

Basically I’m looking for a way to toggle ALL topic-lists to show an excerpt (with some control on length, multi-media and links show/hide etc).


(Sam Saffron) #3

I think we should first look at making our extensibility interfaces allow for this kind of stuff, will have a think at how to structure such a plugin.


(Ajaz) #4

@sam,

Thanks for considering this; I think this feature/add-on will make this platform much much better and extend it to the way people wish to use modern forums.

I look forward to your thoughts and work on this.

If you can give me some basic guidance, I can perhaps help you develop this aspect.


(Spero Koulouras) #5

Just kicking this thread to see if there is any hope for this feature. Please add us to the list of folks that would really like it. My preferred implementation would be a setting on the category screen to allow turning excerpts on/off for all items that belong to a category.


(Spero Koulouras) #6

@sam - any further thoughts on this?


(Sam Saffron) #7

We plan to get to extensibility on the topic list for 1.2 (our next release) I can not make any promises, but we will try to address this.


Discourse 1.2 Extensibility Game Plan
#10

@sam I was wondering if any headway had been made on this? I was looking at your thread: Sam’s personal “minimal” topic list design and was wondering if there was a way to insert the topic excerpt somewhere.

I’ve tried topic.excerpt and list/topic-excerpt which are empty.

I’m assuming it somehow has to get post.cooked and do some processing on it, but I’m not sure how I could get that information in there? I imagine that it should be relatively simple now following this method of overriding the template, no?

I would have thought looking at the /app/models/topic.rb that it would be simply topic.excerpt or is this excerpt only set when a topic is pinned?


(Sam Saffron) #11

This would be a very tricky change, you would need a plugin to amend the way the serializer works.


Show excerpt for all topics via a theme
#12

Is there any chance of a bit of a prod in the right direction then? I’m trying to make a plugin to adjust the serializer, so I’m assuming I need a plugin that overrides /app/serializers/topic_list_item_serializer.rb

In my plugin.rb:

after_initialize do
	require_dependency File.expand_path('../topic_list_item_serializer.rb', __FILE__)
end

and in the same folder, topic_list_item_serializer.rb which is a complete copy of the core file, which is necessary I assume according to this post, and I’ve added an attribute my_custom_excerpt (for example).

with the addition:

def my_custom_excerpt
  object.first_post.cooked
end

(in my case, I’ve required Nokogiri to do some processing on cooked to strip images and br’s, and I feel like I must be doing something wrong now because I feel like I shouldn’t be doing this kind of logic/work in the serializer:

def my_custom_excerpt
  test_excerpt =  Nokogiri::HTML(object.first_post.cooked).search('p')
  test_excerpt.search('.//img').remove
  test_excerpt.search('.//br').remove
  test_excerpt
end

And then in the header customization in /admin/customize/css_html Header:

<script type='text/x-handlebars' data-template-name='list/topic_list_item.raw'>
  ...
  {{{ topic.my_custom_excerpt }}}
  ...
</script>

This isn’t working as it’s outputting something like: src,/uploads/default/19/a06b4c07fd2c8e1d.png,width,690,height,460, I assume due to an issue rendering the HTML out etc…

I feel like I’m close but probably not approaching this the right way, @sam if you or someone could just nudge me in the right direction it would be so greatly appreciated.


(Maya Lesh) #13

We are also using the simplified display and would like to add topic excerot for all posts. Is there progress in this direction, or some tips on how to do this?


#14

How about just a simple tooltip on mouseover of the topic title?


(Tom Newsom) #15

No good on touch screens


#16

[quote=“Tom_Newsom, post:15, topic:7368, full:true”]
No good on touch screens
[/quote]Duh. But how about adding tooltip previews as a desktop only feature until a better solution is found/implemented?


(Angus McLeod) #17

Just playing around with this now, it’s relatively simple to ‘turn on’ excerpts for all topics in the discovery stream.

Please note, this is just the basic way to make all items in the discovery stream have an excerpt. I make no promises about performance (or anything else) :smile:

I’m assuming you’re already familiar with the basics of how to write a plugin.

  1. Add this to your plugin.rb file

    ``
    after_initialize do

     require 'listable_topic_serializer'
    
     class ::ListableTopicSerializer
    
       def include_excerpt?
         true
       end
    
     end
    

    end
    ``

    Basically, this reopens the ListableTopicSerializer class and overwrites the include_excerpt property to always return true (see further here). Normally ‘include_excerpt’ is defined as pinned, hence excerpts are only included in pinned posts.

  2. Overwrite /templates/list/topic-list-item.raw.hbs by copying the template (with the same file path) into your plugin.

  3. Remove the {{#if expandPinned}} {{/if}} wrapped around {{raw "list/topic-excerpt" topic=topic}} in the main-link

Viola, you now have topic excerpts for all items in the discovery stream.


Show excerpt for all topics via a theme
(Kane York) #18

Okay, now taking that it’s pretty easy to turn this into a core feature.

  def include_excerpt?
    SiteSetting.excerpts_for_all_topics || original_condition
  end

and

  expandPinned: function() {
    return this.siteSettings.excerpts_for_all_topics || this.get('something');
  }.property('something'),

(Jay Pfaffman) #19

Is it possible to do something similar to this to include the username of the poster before the topic?


(Angus McLeod) #20

Hey. Not similar, but it’s definitely possible. It looks like that info is already included in the topic data sent to the client (see attached). So what you need to do is write a plugin that changes the appropriate topic list template to display that data. This is probably doable by just overriding a handlebars template, but you may need to reopen a controller or somesuch and add a method that decorates the template with the appropriate data. You won’t need to change any server logic (which was required for the topic-excerpt).


(Pad Pors) #21

I couldn’t make it work yet. nochanges happen after i follow the recepie. any clue?

just to make sure i got it right, i’ve a excerpt-plugin folder with 2 files:

  1. plugin.rb with the mentioned code in it.
  2. topic-list-item.raw.hbs with omitted if + /if lines.

anything wrong?


(Angus McLeod) #22

Hey,

  1. Are you sure the plugin is being picked up on your instance properly?

  2. Have a re-read of the plugin tutorials to make sure you haven’t missed anything about making a plugin (e.g. right folder structure)

  3. Take a look at how quick messages adds an excerpt to private messages.

  4. Publish your plugin repo so I can take a look.