Uses a docpad configuration file to specify template data that we can use in our document to generate absolute urls.
-
-
Save balupton/3939146 to your computer and use it in GitHub Desktop.
module.exports = | |
# ================================= | |
# Template Data | |
# These are variables that will be accessible via our templates | |
templateData: | |
# Site Information | |
site: | |
# Site Production URL | |
url: 'http://your-website.com' | |
# ----------------------------- | |
# Helpers | |
# Get the Absolute URL of a document | |
getUrl: (document) -> | |
return @site.url + (document.url or document.get?('url')) | |
Via helper: <a href="<%= @getUrl(@document) %>">visit me</a> | |
Without helper: <a href="<%= @site.url+@document.url %>">visit me</a> |
WIP: https://github.com/Hypercubed/docpad-plugin-geturl/
Comments welcome.
Is there any way to get the actual relative URL, see http://stackoverflow.com/questions/19252513/how-to-get-the-relative-url-for-the-rendered-document ?
I need to output for several different websites which share some content but also have unique content. Basically the sites are focused on specific countries, but some content references multiple countries (and so is on all sites (and this is fine with Google).
E.g.,
nepal.com/projects // unique content to this site
nepal.com/summer-volunteering-in-south-asia // shared content
india.com/projects // unique content to this site
nepal.com/summer-volunteering-in-south-asia // shared content (identical to above)
How should I organize using docpad? Should this be two different docpad installations where I manually copy the shared content? Or can this be one docpad but use folders/subfolders such as:
/india-projects
/summer-volunteering-in-south-asia
/nepal-projects
And then produce multiple static sites (or a single site with inbound redirection/rewrite of base URL based on site request)?
I'm surprised there is not a push to solve this issue. One of the first things I do while building and testing a new site is deploy it to github pages,... but ghpages are stored in a sub-directory so all navigation links, scripts, and styles generated by the docpad skeletons are broken. In any event here is my solution.
I add a helper that fixes absolute urls (urls starting with a forward slash). The helper function takes strings, documents, and arrays so it is multi-use. I thought about making this a plugin but I'm not sure if this is the best (or even good) solution.
Here is my code:
Used like this
or for scripts and styles