From c940904f011d602d44ca29720926e2d19556140e Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sun, 7 Jul 2024 14:39:28 -0700 Subject: [PATCH] Code duplications removed and memory usage improved Signed-off-by: Matt Friedman --- ...cgirr83_top_five_topiclist_row_append.html | 8 +++--- .../template/event/topiclist_row_append.html | 27 +++++-------------- styles/all/template/topicpreview.html | 20 +++++++------- styles/all/template/topicpreview_macro.html | 11 ++++++++ 4 files changed, 32 insertions(+), 34 deletions(-) create mode 100644 styles/all/template/topicpreview_macro.html diff --git a/styles/all/template/event/rmcgirr83_top_five_topiclist_row_append.html b/styles/all/template/event/rmcgirr83_top_five_topiclist_row_append.html index a7dd4bd..6007d90 100644 --- a/styles/all/template/event/rmcgirr83_top_five_topiclist_row_append.html +++ b/styles/all/template/event/rmcgirr83_top_five_topiclist_row_append.html @@ -1,4 +1,4 @@ -{% if top_five_topic.TOPIC_PREVIEW_FIRST_POST %} - {% set preview = top_five_topic %} - {% include '@vse_topicpreview/topicpreview.html' %} -{% endif %} +{% import '@vse_topicpreview/topicpreview_macro.html' as macro %} + +{# Display topic preview in Top Five extension #} +{{ macro.renderTopicPreview(top_five_topic) }} diff --git a/styles/all/template/event/topiclist_row_append.html b/styles/all/template/event/topiclist_row_append.html index c0f2759..1cb66eb 100644 --- a/styles/all/template/event/topiclist_row_append.html +++ b/styles/all/template/event/topiclist_row_append.html @@ -1,29 +1,16 @@ +{% import '@vse_topicpreview/topicpreview_macro.html' as macro %} + {# display topic preview in view forum #} -{% if topicrow.TOPIC_PREVIEW_FIRST_POST %} - {% set preview = topicrow %} - {% include '@vse_topicpreview/topicpreview.html' %} -{% endif %} +{{ macro.renderTopicPreview(topicrow) }} {# display topic preview in search results #} -{% if searchresults.TOPIC_PREVIEW_FIRST_POST %} - {% set preview = searchresults %} - {% include '@vse_topicpreview/topicpreview.html' %} -{% endif %} +{{ macro.renderTopicPreview(searchresults) }} {# display topic preview in Similar Topics extension #} -{% if similar.TOPIC_PREVIEW_FIRST_POST %} - {% set preview = similar %} - {% include '@vse_topicpreview/topicpreview.html' %} -{% endif %} +{{ macro.renderTopicPreview(similar) }} {# display topic preview in Recent Topics extension #} -{% if recent_topics.TOPIC_PREVIEW_FIRST_POST %} - {% set preview = recent_topics %} - {% include '@vse_topicpreview/topicpreview.html' %} -{% endif %} +{{ macro.renderTopicPreview(recent_topics) }} {# DEPRECTATED: @v2.2.1 display topic preview in Top Five extension #} -{% if top_five_topic.TOPIC_PREVIEW_FIRST_POST %} - {% set preview = top_five_topic %} - {% include '@vse_topicpreview/topicpreview.html' %} -{% endif %} +{{ macro.renderTopicPreview(top_five_topic) }} diff --git a/styles/all/template/topicpreview.html b/styles/all/template/topicpreview.html index b3debc2..f7b22c2 100644 --- a/styles/all/template/topicpreview.html +++ b/styles/all/template/topicpreview.html @@ -1,31 +1,31 @@ diff --git a/styles/all/template/topicpreview_macro.html b/styles/all/template/topicpreview_macro.html new file mode 100644 index 0000000..febc8a6 --- /dev/null +++ b/styles/all/template/topicpreview_macro.html @@ -0,0 +1,11 @@ +{% macro renderTopicPreview(context) %} + {% if context.TOPIC_PREVIEW_FIRST_POST %} + {% set preview = { + TOPIC_PREVIEW_FIRST_POST: context.TOPIC_PREVIEW_FIRST_POST, + TOPIC_PREVIEW_LAST_POST: context.TOPIC_PREVIEW_LAST_POST, + TOPIC_PREVIEW_FIRST_AVATAR: context.TOPIC_PREVIEW_FIRST_AVATAR, + TOPIC_PREVIEW_LAST_AVATAR: context.TOPIC_PREVIEW_LAST_AVATAR + } %} + {% include '@vse_topicpreview/topicpreview.html' with preview %} + {% endif %} +{% endmacro %}