DocPad: Absolute URL Helper
Uses a docpad configuration file to specify template data that we can use in our document to generate absolute urls.
|# Template Data|
|# These are variables that will be accessible via our templates|
|# Site Information|
|# Site Production URL|
|# Get the Absolute URL of a document|
|getUrl: (document) ->|
|return @site.url + (document.url or document.get?('url'))|
This doesn't solve my problem =/
When I call for my scripts like:
I can see them on my local instance but not on my github pages instance because the path is different.
What I want do to, is to grab the full url to normalize this like:
Yeah, the environment stuff is pretty new so the docs haven't caught up yet.
Perhaps the following will be better for your use case:
module.exports = # ================================= # Template Data # These are variables that will be accessible via our templates templateData: # ----------------------------- # Site Information site: # Site Production URL url: 'http://zenorocha.github.com/alloyui.com' # ----------------------------- # Helpers # Get the Absolute URL of a document getUrl: (document) -> return @site.url + (document.url or document.get?('url')) # ================================= # Environments environments: development: templateData: site: url: 'http://localhost:9778'
That static environment will turn off things like cleanurls and livereload that are dependent on the node.js server.
The production environment will try and compress and compilations that happen (when supported) versus giving you readable output. E.g. minified stylesheets, html, etc.
When it comes to scripts, styles, etc. called via
<script defer="defer" src="../../vendor/jquery.js"></script>
when rendered document is, say
This would require detecting out path and generating relative path from absolute given. Seems easy. What do you think?
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
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).
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:
And then produce multiple static sites (or a single site with inbound redirection/rewrite of base URL based on site request)?