Swiftpack.co - hishnash/PublishFilePipeline as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by hishnash.
hishnash/PublishFilePipeline 0.0.5
File Prossinging Pipeline for the Publish blogging engine.
⭐️ 0
🕓 25 weeks ago
macOS
.package(url: "https://github.com/hishnash/PublishFilePipeline.git", from: "0.0.5")

PublishFilePipeline

This package aims to provide a simple way to add file prossing pipelines to the Resources when using Publish.

common usage is to add a hash to the resources filenames. This package supports doing this, and ensures that the links throughout your blog that link to these hased files are correct.

Usage

// This will generate your website using the built-in Foundation theme:
try MyWebSite().pipelinePublish(
    withTheme: .container,
    plugins: [
        .pipeline(for: try! RegEx(pattern: #".css$"#), with: [StringReplaceStage(), CacheBustStage()]),
        .pipeline(with: [CacheBustStage()]),
        .markdownPipeline
    ]
)

This includes 3 differnt plugins.

Handing txt based Resources that link to other Resources

When adding the hash of a file to its filename it is important that all links to this file are updated, this includes links to this file that exist from within your Resources such as CSS that might sometimes like the background images.

.pipeline(for: try! RegEx(pattern: #".css$"#), with: [StringReplaceStage(), CacheBustStage()])

This will setup a filter to match any file ending in .css`, so that first the file has any refrences to other `Resources replaced with the final output filename then it is hashed. This means that if a background image is changed (and thus its hashed filename changes) any css that points at this image will also be changed and its hash will be updated so that browser cache issues to not impact your users.

Handling any other files

.pipeline(with: [CacheBustStage()]),

This should be the last .pipeline plugin you define it will catch any files that are not matched by the above filters. In this case it will then hash them and copy the file with the hash in the filename.

Handeling links to your files

.markdownPipeline

This will attempt to match any links you have to files in your Resousre folder and change them to point to the new filenames (that include the hash).

In your theme template you might also need to refrences files (such as css etc). You can ask for the output (hashed) filename:

site.resourcePath(for: "/static/red-moa.svg", with: context)

GitHub

link
Stars: 0
Last commit: 4 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

v0.0.1
2 years ago

First Release more to come.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics