Git Product home page Git Product logo

docpad-plugin-associatedfiles's Introduction

Associated Files Plugin for DocPad

Travis CI Build Status NPM version NPM downloads Dependency Status Dev Dependency Status
GitHub Sponsors donate button Patreon donate button Flattr donate button Liberapay donate button Buy Me A Coffee donate button Open Collective donate button crypto donate button PayPal donate button Wishlist browse button

This plugin streamlines finding associated files for a particular document in DocPad, which is useful for:

  • getting images for a gallery
  • getting downloads for an article
  • etc. etc.

Install

docpad install associatedfiles

Usage

The way it works is by looking into src/files/associated-files/#{document.associatedFilesPath or document.basename} for files. Where associatedFilesPath is set in your document's meta data, and if it doesn't exist it will use the document's basename (e.g. the basename of my-holiday-2012.html.eco is my-holiday-2012). Any files inside that path will be associated to your document, and retrieveable by @getDocument().getAssociatedFiles()

Lets see how this works, we have the document src/documents/my-holiday-2012.html.eco:

---
title: My Holiday in 2012
---

<h2>Here are some great photos from our trip</h2>

<% for file in @getDocument().getAssociatedFiles().toJSON(): %>
<p>
	<h3><%= file.title or file.name %></h3>
	<img src="<%= file.url %>" title="<%= file.title or file.name %>" />
</p>
<% end %>

Then we will stick a few images inside our path: src/files/associated-files/my-holiday-2012. And we'll end up with the rendered result:

<h2>Here are some great photos from our trip</h2>

<p>
	<h3>sweet-sweet-beach.jpg</h3>
	<img src="/associated-files/my-holiday-2012/sweet-sweet-beach.jpg" title="sweet-sweet-beach.jpg" />
</p>

<p>
	<h3>sweet-sweet-icecream.jpg</h3>
	<img src="/associated-files/my-holiday-2012/sweet-sweet-icecream.jpg" title="sweet-sweet-icecream.jpg" />
</p>

Configure

Defaults

The default configuration for this plugin is the equivalant of adding the following options to your DocPad configuration file:

plugins:
	associatedfiles:
		# The paths for the associated files.
		associatedFilesPath: 'associated-files'

		# Whether to use relative base paths for the document. This would
		# use associated-files/subfolder/myarticle/image.jpg instead of
		# associated-files/myarticle/image.jpg.
		useRelativeBase: false

Template Configuration

It is possible to override the default configuration on a per-template basis:

---
associatedFilesRelative: true
associatedFilesPath: './myfolder'
---

<% for file in @getDocument().getAssociatedFiles().toJSON(): %>
<p>
	<h3><%= file.title or file.name %></h3>
	<img src="<%= file.url %>" title="<%= file.title or file.name %>" />
</p>
<% end %>

History

Discover the release history by heading on over to the HISTORY.md file.

Contribute

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

Backers

Maintainers

These amazing people are maintaining this project:

Sponsors

No sponsors yet! Will you be the first?

GitHub Sponsors donate button Patreon donate button Flattr donate button Liberapay donate button Buy Me A Coffee donate button Open Collective donate button crypto donate button PayPal donate button Wishlist browse button

Contributors

These amazing people have contributed code to this project:

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

License

Unless stated otherwise all works are:

and licensed under:

docpad-plugin-associatedfiles's People

Contributors

balupton avatar bobvanderclay avatar dependabot[bot] avatar jonathanh32 avatar robloach 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.