Skip to content
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

Open
balupton opened this issue Jan 17, 2013 · 7 comments
Open

Handle absolute urls natively? #402

balupton opened this issue Jan 17, 2013 · 7 comments

Comments

@balupton
Copy link
Member

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.

@Hypercubed
Copy link

Working on a plugin: https://github.com/Hypercubed/docpad-plugin-geturl/

@hurrymaplelad
Copy link

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.

@Hypercubed
Copy link

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.

@hurrymaplelad
Copy link

@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.

@balupton
Copy link
Member Author

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.

@balupton
Copy link
Member Author

balupton commented Sep 5, 2013

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")

@balupton
Copy link
Member Author

balupton commented Mar 4, 2014

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:

  • document.url will become an absolute url, it will have site.url prepended
  • document.relativeUrl will become the previous URL

balupton added a commit to docpad-archive/docpad-skeleton-kitchensink that referenced this issue Mar 4, 2014
@balupton balupton added this to the Nice to have milestone Jul 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants