https://github.com/hypercubed/docpad-plugin-geturl
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.
https://github.com/hypercubed/docpad-plugin-geturl
Last synced: about 1 year ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/hypercubed/docpad-plugin-geturl
- Owner: Hypercubed
- License: other
- Created: 2013-06-11T09:38:13.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2013-12-20T06:32:07.000Z (over 12 years ago)
- Last Synced: 2024-12-21T22:08:28.643Z (over 1 year ago)
- Language: CoffeeScript
- Homepage:
- Size: 141 KB
- Stars: 9
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Get Url Plugin for [DocPad](http://docpad.org)
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](http://en.wikipedia.org/wiki/Permissive_free_software_licence) [MIT License](http://creativecommons.org/licenses/MIT/)
Copyright © 2013+ J. Harshbarger