Code Monkey home page Code Monkey logo

docpad-plugin-geturl's Introduction

Get Url Plugin for DocPad

Take a href URL and an optional base URL and resolve them as a browser would for an anchor tag. Useful for calculating URLs relative to @site.url. See examples below.

Install

npm install --save docpad-plugin-geturl

Install for testing

git clone https://github.com/Hypercubed/docpad-plugin-geturl.git
cd docpad-plugin-geturl
npm install
make compile

Test

make test

Configuration

Requires a @site.url:

# ...
  templateData:
		site:
			url: 'http://localhost:9778'
# ...

Examples

Absolute

Call Returned
@getUrl('/') http://localhost:9778/
@getUrl('/test') http://localhost:9778/test
@getUrl('/test/') http://localhost:9778/test/
@getUrl('/test.html') http://localhost:9778/test.html

Relative

Call Returned
@getUrl('') http://localhost:9778/document.md
@getUrl('test.html') http://localhost:9778/test.html
@getUrl('../test.html') http://localhost:9778/test.html

External

Call Returned
@getUrl('//test.com') http://test.com/
@getUrl('http://test.com') http://test.com/
@getUrl('https://test.com') https://test.com/
@getUrl('test.html', 'https://test.com') https://test.com/test.html
@getUrl('../test.html', 'https://test.com/sub/') https://test.com/test.html

Objects

Call Returned
@getUrl(@document) http://localhost:9778/document.md

Arrays

Call Returned
@getUrl(['/', '/test', 'test']) http://localhost:9778/,http://localhost:9778/test,http://localhost:9778/test
@getBlock('styles').add(@getUrl(@site.styles)).toHTML() <link rel="stylesheet" href="http://localhost:9778/root_style.css" /><link rel="stylesheet" href="http://localhost:9778/sub_style.css" />

Arrays of objects

Call Returned
@getUrl(@getCollection('documents')) http://localhost:9778/sub/documents.md,http://localhost:9778/document.md

License

Licensed under the incredibly permissive MIT License
Copyright © 2013+ J. Harshbarger

docpad-plugin-geturl's People

Contributors

hypercubed avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.