Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Note that in this example we've added the count and weight here as HTML5 data fi
- *collectionName* : The collection containing your tag index pages. This should probably be the same as specified for the tags plugin.
- *getTagWeight* : Override the function used to generate the tag weights (see below).
- *logLevel*: Override the log level for log messages from this plugin. Defaults to 'info'.
- *getTaggedFiles*: The function to get all source files. Override the default `docpad.getFiles({tags: $has: tag})` to use only a filtered collection like `docpad.getFiles({tags: {$has: tag}, isPublished:true})`.

### Customising the weight function

Expand Down
5 changes: 4 additions & 1 deletion src/tagcloud.plugin.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module.exports = (BasePlugin) ->
config:
collectionName: 'tags'
logLevel: 'info'
getTaggedFiles: (docpad, tag) ->
return docpad.getFiles({tags: $has: tag})

getTagWeight: (count, maxCount) ->
# apply logarithmic weight algorithm
Expand All @@ -26,14 +28,15 @@ module.exports = (BasePlugin) ->
renderBefore: ({collection, templateData}, next) ->
config = @getConfig()
docpad = @docpad
plugin = @

@tagCloud = {} # reset every time renderBefore is triggered
@maxCount = 0

tagDocs = docpad.getCollection(config.collectionName)
tagDocs?.forEach (doc) =>
tag = doc?.get('tag')
taggedfiles = docpad.getFiles({tags: $has: tag})
taggedfiles = config.getTaggedFiles.call(plugin, docpad, tag)
count = taggedfiles?.length or 0

@tagCloud[tag] ?=
Expand Down