New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle absolute urls natively? #402
Comments
Working on a plugin: https://github.com/Hypercubed/docpad-plugin-geturl/ |
Built a grunt task to handle a similar problem by transforming absolute paths to relative paths after a static generate. No template changes or tedious helpers required. Could be fairly easily extended to transform absolute paths to absolute URLs instead of relative paths. |
I worry that the search and replace option will change urls it shouldn't (for example in code examples). For what it's worth, I also don't think the getUrl plugin is the best option, although I am using it everywhere now. I'm wondering if the best solution may be to have docpad always return urls relative to the root (index.html vs. /index.html) and add a base href tag to the template? I think this is how it is done in other CMSs, although I remember struggling one time with # anchors. |
@Hypercubed I share your concern about overzealous replacement. So far I've been expanding the search expressions as specific cases come up. Test cases greatly appreciated. I'm also optimistic that if regular expressions fall short, parsing and traversing a legit DOM and CSSOM from the source will pickup the slack while maintaining the existing interface. I prefer less magic on DocPad's part. So far, all the use cases I've seen involve statically generated sites, where a build time transformation is plenty. |
Having a grunt task or plugin for converting our urls to relative urls sounds like a great idea. Having such magic in the DocPad core could cause a lot of additional complexity, and as additional complexity introduces unforeseen complications and consequences, I'd really like to avoid adding anything to the core to handle select edge cases, as ideally the core should be as simple as possible and where every line of code is useful to everyone - it's a crazy ideal, but one that should be strived for regardless. |
I was able to come up with the following docpad configuration that worked well for my use case: # =================================
# 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://webwrite.github.io/inlinegui/"
# =================================
# 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:
# Render Document
renderDocument: (opts) ->
return if 'development' in @docpad.getEnvironments()
if opts.extension is 'html'
siteUrl = @docpad.getConfig().templateData.site.url.replace(/\/+$/, '')
opts.content = opts.content.replace(/(['"])\/([^\/])/g, "$1#{siteUrl}/$2") |
This should definitely be handled natively. I just discovered how annoying this is when working with multiple environments. v6.64.0 has made the first step on this. Will release v6.65.0 with this change later on. Current plan is:
|
Bugs are: - docpad/docpad#767 - docpad/docpad#807 This would also be nice to have: - docpad/docpad#402
See http://stackoverflow.com/q/14245520/130638 and https://gist.github.com/3939146
Want to back this issue? Place a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: