Per-folder resources for Publish
A Publish plugin that copies per-folder resources to the same location in the static site output.
By default, Publish’s
copyResources() step copies a single file of resources from the unpublished content folder to the static site output folder. This extension traverses the content folder to find resources in any folder and copies them to an output folder with the same folder path.
This may be useful if, for example, your site contains blog posts or other individual pages where inline images or other resources are in the same directory as the post’s Markdown file.
For purposes of this plugin, “resources” means anything that’s not a Markdown or text file.
Note: Currently this plugin depends on a fork of Publish, which adds the
shouldIgnore(name:) function to
Website. If this seems useful to you, please comment on the pull request.
To install it into your Publish package, add it as a dependency within your
let package = Package( ... dependencies: [ ... .package(name: "PerFolderResourcesPublishPlugin", url: "https://github.com/atomicbird/PerFolderResourcesPublishPlugin", .branch("main")) ], targets: [ .target( ... dependencies: [ ... "PerFolderResourcesPublishPlugin" ] ) ] ... )
.package entry above it’s currently necessary to use
.branch("main") but with luck the PR mentioned earlier will be accepted and then this can be changed to a version requirement.
For more information on how to use the Swift Package Manager, check out this article, or its official documentation.
First import PerFolderResourcesPublishPlugin wherever you’d like to use it:
The plugin can then be used within any publishing pipeline like this:
import PerFolderResourcesPublishPlugin ... try DeliciousRecipes().publish(using: [ ... .installPlugin(.copyPerDirectoryResources()), ... ])
This plugin can be installed at any point in the publishing process. It does not depend on or affect other steps.
If you’re using a custom folder in the
addMarkdownFiles publishing step, pass the same folder as the argument to this plugin:
import PerFolderResourcesPublishPlugin ... try DeliciousRecipes().publish(using: [ ... .addMarkdownFiles(at: myContentPath), ... .installPlugin(.copyPerDirectoryResources(at: myContentPath)), ... ])