Link Plugin for DocPad
Take the document's id
and generate the corresponding HTML link.
Prevents the breaking of links when a document is moved to a different directory, or gets renamed. Also keeps links DRY, since the link title and text is pulled from the document's meta data.
npm install --save docpad-plugin-link
git clone https://github.com/oleersoy/docpad-plugin-link.git
cd docpad-plugin-link
npm install
make compile
make test
Override the following defaults when necessary:
# ...
{
templateData:
site:
url: 'http://localhost:9778/base'
}
# ...
Run the tests to see the below executed.
Document Location | Document ID | Document title | Call | Returned |
---|---|---|---|---|
root_document.md.eco |
1 | Root Meta Data Title for 1 | @link(1) |
<%- @link(1)%> |
root_document.md.eco |
1 | Root Meta Data Title for 1 | @link(1, {title: "Custom Title 1"}) |
<%- @link(1, {title: "Custom Title 1"})%> |
root_document.md.eco |
1 | Root Meta Data Title for 1 | @link(1, {text: "Custom Text 1"}) |
<%- @link(1, {text: "Custom Text 1"})%> |
root_document.md.eco |
1 | Root Meta Data Title for 1 | @link(1, {title: "Custom Title 1", text: " Custom Text 1"}) |
<%- @link(1, {title: "Custom Title 1", text: "Custom Text 1"})%> |
sub/sub_document.md.eco |
2 | Sub Meta Data Title for 2 | @link(2) |
<%- @link(2)%> |
sub/sub_document.md.eco |
2 | Sub Meta Data Title for 2 | @link(2, {title: "Custom Title 2"}) |
<%- @link(2, {title: "Custom Title 2"})%> |
sub/sub_document.md.eco |
2 | Sub Meta Data Title for 2 | @link(2, {text: "Custom Text 2"}) |
<%- @link(2, {text: "Custom Text 2"})%> |
sub/sub_document.md.eco |
2 | Sub Meta Data Title for 2 | @link(2, {title: "Custom Title 2", text: " Custom Text 2"}) |
<%- @link(2, {title: "Custom Title 2", text: "Custom Text 2"})%> |
See License.md
Copyright © 2013+ Ole Ersoy