Swiftpack.co - c0dedbear/SVGPublishPlugin as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
c0dedbear/SVGPublishPlugin
Pure SVG files inside yours Publish projects.
.package(url: "https://github.com/c0dedbear/SVGPublishPlugin.git", from: "0.1.3")

SVGPublishPlugin

Tests Swift 5.3 Swift Package Manager Mac Publish Plugin

Use pure SVG files in your Publish projects💥

Installation

Add the package to your SPM dependencies.

.package(name: "SVGPublishPlugin", url: "https://github.com/c0dedbear/SVGPublishPlugin", from: "0.1.0"),

Usage

  1. Put your .svg files at the "Resources/svg" folder (it's default path, but you can changed it).
  2. Install the plugin using publishing pipeline like this:
​```swift
import SVGPublishPlugin
...
try YourWebSite().publish(
	withTheme: .bearlogsTheme,
	additionalSteps: [
...
	],
	plugins: [
		.svgPlugin(),
...
	]
)

☝Note that if your svg files not placed in the "Resources/svg", you must use 'folderPath' parameter of '.svgPlugin' method.

⚠️ There must be at least one file with .svg extension, in other case publish will throw an error on the install plugin step.

  1. Use within .svg node like this:
// Note that you don't need import plugin in places where you build your HTML

func makePageHTML(for page: Page, context: PublishingContext<Site>) throws -> HTML {
	HTML(
		.lang(context.site.language),
		.head(for: page, on: context.site),
		.body(
			.header(for: context, selectedSection: nil),
			.a(
			   .class(CSS.footerSectionTitle),
			   // File named `rss.svg` placed on folder path typed when installing plugin.
			   .svg("rss"),
			   .text("RSS feed"),
			   .href(Path.defaultForRSSFeed),
			)
		)
	)
}
  1. Also you can put it additional parameters right into your svg file:
...
.svg("rss", parameters: .class(CSS.FooterRssIcon), .width(20), .height(20)),
...

.width and height - size of svg into pixels.

.classString - stylesheet's class name string

.class - StrongTypedCSS conformed class (see more on https://github.com/c0dedbear/StrongTypedCSSPublishPlugin)

.classes - array of StrongTypedCSS-conformed cases

  1. For a more convenience usage, I recommend to create an enum conformed to SVGFileNameCase protocol, which contains names of the svg files in your folder. And use it this way:
...
import SVGPublishPlugin
....
enum SVG: String, SVGFileNameCase {
	case logo
	case search
	case rss
	case backToTop
}

// Inside of any HTML Node:
...
.svg(SVG.logo, parameters: .class(CSS.logoForFeaturedPosts)),
...

Author

logo Mikhail Medvedev | https://bearlogs.ru

GitHub

link
Stars: 0
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Dependencies

Release Notes

0.1.3
2 weeks ago

Updated for Swift 5.4

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