Blog

Confluence User Macro: Blog Posts Social

20. February 2019 | 2 Minuten zum Lesen

Tags: atlassian, confluence, user-macros, blog

From time to time there is a need to write a little user macro for Confluence when implementing solutions to customers at my employer Hagen Management. User macros can be a little helper to display content or administrative tasks. In this case the problem is, that there are only three options to show a list of blogposts.

On the installations of our customers we prefer to display blogposts with an image of the author, the author and the creation date. With default macros the only way is to additionally show the excerpt or the entire post. With the Blog Post Social Macro you are able to hide the content easily.

Screenshot of Blog Posts Social Macro

We added a little CSS styling in order to display a compact list of the posts. You are also able to enter the number of posts to display, restrict to spaces or labels and hide the content.

Here is the code:

## Macro title: Blog Posts Social
## Macro has a body: N
##
## Developed by: Thomas Egger
## Source: 
## Adapted by:
## Date created: 05/12/2018
## Installed by:
 
## @param Number:title=Maximum Number of Blog Posts|type=string|required=false|desc=Default is 10.
## @param Spaces:title=Restrict to these Spaces|type=string|required=false|desc=These are case-sensitive. Separate each item with a comma or single space. Example: SPACEKEY,@personal. If not specified, all spaces are searched.
## @param Labels:title=Restrict to these Labels|type=string|required=false|desc=Separate each label with a comma or single space.
## @param HideExcerpt:title=Hide excerpt|type=boolean|default=true|desc=Do you want to hide the excerpt content?
 
<style type="text/css">
.blog-post-listing-social .blog-post-listing {
  border-top: none;
  padding-top: 0.8rem;
  padding-bottom: 0.8rem;
}
.blog-post-listing-social .blog-post-listing .logoBlock {
  top: 0.5rem;
}
.blog-post-listing-social .blog-post-listing .logo-heading-block {
  margin-bottom: 0;
}
.blog-post-listing-social .blog-post-listing .logo-heading-block a.blogHeading {
  font-weight: bold !important;
  font-size: 1rem;
  line-height: 1.5 !important;
}
.blog-post-listing-social .blog-post-listing .logo-heading-block .blogHeading .page-metadata {
  font-size: 0.68rem;
  margin-top: 0;
  line-height: 1.5 !important;
}
.blog-post-listing-social .blog-post-listing .wiki-content {
    font-size: 0.8rem;
    margin-top: 0.6rem;
    line-height: 1.5;
}
.blog-post-listing-social.hide-content .blog-post-listing .wiki-content {
  display: none;
}
.blog-post-listing-social .blog-post-listing .endsection {
  display: none;
}
</style>
#if (!$paramNumber) #set ($paramNumber = 10) #end
#if (!$paramSpaces) #set ($paramSpaces = "@all") #end
#if (!$paramLabels) #set ($paramLabels = "") #end
 
<div class="blog-post-listing-social #if ($paramHideExcerpt == "true") hide-content #end">
    <ac:structured-macro ac:name="blog-posts" ac:schema-version="1">
        <ac:parameter ac:name="max">$paramNumber</ac:parameter>
        <ac:parameter ac:name="spaces">
            <ri:space ri:space-key="$paramSpaces"/>
        </ac:parameter>
        <ac:parameter ac:name="sort">creation</ac:parameter>
        <ac:parameter ac:name="reverse">true</ac:parameter>
        <ac:parameter ac:name="content">excerpts</ac:parameter>
        <ac:parameter ac:name="labels">$paramLabels</ac:parameter>
    </ac:structured-macro>
</div>