lucor / docpad-plugin-navlinks Goto Github PK
View Code? Open in Web Editor NEWDocpad plugin which adds the ability to generate a navbar for documents with links to the next and previous document of the specified collection
License: Other
Docpad plugin which adds the ability to generate a navbar for documents with links to the next and previous document of the specified collection
License: Other
For example I need to translate "Previous Post:" and "Next Post:" into another language and add some extra markup.
Just upgraded to the latest version of docpad (6.65.0) and latest version of all my plugins. Prior to the upgrade building the website worked fine. After the upgrade I get the following error:
ReferenceError: docpad is not defined
at NavLinksPlugin.renderBefore (C:\documents\personal\mindvortex\src\node_modules\docpad-plugin-navlinks\out\navlinks.plugin.js:30:11)
at ambi (C:\documents\personal\mindvortex\src\node_modules\docpad\node_modules\event-emitter-grouped\node_modules\ambi\out\lib\ambi.js:23:18)
at Task.<anonymous> (C:\documents\personal\mindvortex\src\node_modules\docpad\node_modules\event-emitter-grouped\out\lib\event-emitter-grouped.js:45
:23)
at ambi (C:\documents\personal\mindvortex\src\node_modules\docpad\node_modules\event-emitter-grouped\node_modules\ambi\out\lib\ambi.js:23:18)
at fire (C:\documents\personal\mindvortex\src\node_modules\docpad\node_modules\event-emitter-grouped\node_modules\taskgroup\out\lib\taskgroup.js:174
:25)
at b (domain.js:183:18)
at Domain.run (domain.js:123:23)
at Task.fire (C:\documents\personal\mindvortex\src\node_modules\docpad\node_modules\event-emitter-grouped\node_modules\taskgroup\out\lib\taskgroup.j
s:184:25)
at processImmediate [as _immediateCallback] (timers.js:336:15)
The configuration looks like:
# The DocPad Configuration File
# It is simply a CoffeeScript Object which is parsed by CSON
docpadConfig = {
# =================================
# plugins
plugins:
navlinks:
collections:
posts: -1
datefromfilename:
removeDate: false
# =================================
# DocPad collections
collections:
pages: ->
@getCollection("html").findAllLive({isPage:true},[{order:1}]).on "add", (model) ->
model.setMetaDefaults({layout:"default"})
posts: (database) ->
database.findAllLive({relativeOutDirPath:'posts'},[{date:-1}]).on "add", (model) ->
model.setMetaDefaults({layout:"post"})
projects: ->
@getCollection('html').findAllLive({relativeOutDirPath:'projects'},[{title:1}]).on "add", (model) ->
model.setMetaDefaults({layout:"project"})
frontpage: ->
@getCollection("html").findAllLive({relativeOutDirPath: $in: ['posts','projects']},[{date: -1}])
# =================================
# Template Data
# These are variables that will be accessible via our templates
# To access one of these within our templates, refer to the FAQ: https://github.com/bevry/docpad/wiki/FAQ
templateData:
# Specify some site properties
site:
# The production url of our website
url: "http://www.petrikvandervelde.nl"
# Here are some old site urls that you would like to redirect from
oldUrls: ["http://pvandervelde.github.io/"]
# The default title of our website
title: "Mind Vortex"
# -----------------------------
# Helper Functions
# Get the prepared site/document title
# Often we would like to specify particular formatting to our page's title
# we can apply that formatting here
getPreparedTitle: ->
# if we have a document title, then we should use that and suffix the site's title onto it
if @document.title
"#{@document.title} | #{@site.title}"
# if our document does not have it's own title, then we should just use the site's title
else
@site.title
# Get the prepared site/document description
getPreparedDescription: ->
# if we have a document description, then we should use that, otherwise use the site's description
@document.description or @site.description
# Get the prepared site/document keywords
getPreparedKeywords: ->
# Merge the document keywords with the site keywords
@site.keywords.concat(@document.keywords or []).join(', ')
# =================================
# DocPad Events
# Here we can define handlers for events that DocPad fires
# You can find a full listing of events on the DocPad Wiki
events:
# Server Extend
# Used to add our own custom routes to the server before the docpad routes are added
serverExtend: (opts) ->
# Extract the server from the options
{server} = opts
docpad = @docpad
# As we are now running in an event,
# ensure we are using the latest copy of the docpad configuraiton
# and fetch our urls from it
latestConfig = docpad.getConfig()
oldUrls = latestConfig.templateData.site.oldUrls or []
newUrl = latestConfig.templateData.site.url
# Redirect any requests accessing one of our sites oldUrls to the new site url
server.use (req,res,next) ->
if req.headers.host in oldUrls
res.redirect(newUrl+req.url, 301)
else
next()
}
# Export our DocPad Configuration
module.exports = docpadConfig
Date::getMonthName = () ->
months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]
months[this.getMonth()]
Collections' last post has a next button that jumps into first post of the collection. I think like the first post last post shouldn't have a next button because it would confuse the readers.
(1)
navLinks = @getDocument().get('navlinks')
This needs an "if (navLinks != null)" wrapping the subsequent block as not all pages may end up with navlinks.
(2)
The "Next post" text is followed by the wrong title:
<a href="#{navLinks.url.next}" title="Next Post: #{navLinks.title.prev}" ...
s/prev/next/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.