A dynamic sitemap generator for Vapor

Overview

Vapor Sitemap

A dynamic sitemap generator for Vapor.

Setup

Add the package to your Package.swift file:

let package = Package(
    // ...
    dependencies: [
        // 💧 A server-side Swift web framework.
        .package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
        .package(url: "https://github.com/vapor-community/vapor-sitemap.git", from: "1.0.0"), // Add this line
    ],
    targets: [
        .target(
            name: "App",
            dependencies: [
                .product(name: "Vapor", package: "vapor"),
                .product(name: "VaporSitemap", package: "vapor-sitemap"), // Add this line
            ]
        ),
    ],
    // ...
)

Usage

First, we need to create some functions to tell to the middleware what to do:

isSitemap(_ req: Request) -> Bool

The goal of this function is to tell the middleware if it should handle a path or not. A basic implementation is this one:

func isSitemap(_ req: Request) -> Bool {
    return req.url.path == "/sitemap.xml"
}

With this implementation, you tell to the middleware to handle only /sitemap.xml.

In some cases, you may want to generate multiple sitemaps. To do so, just handle all the path you want in this function.

generateURLs(_ req: Request) -> [SitemapURL]

The goal of this function is to give all the URLs to put in the specified sitemap. An example implementation is this one:

func generateURLs(_ req: Request) -> [SitemapURL] {
    let prefix = "https://www.example.com/"
    let paths = ["home", "page1", "folder/page2"]
        
    return paths.map { path in
        prefix + path
    }
    .map(SitemapURL.init)
}

Final step

In your configure.swift, add the corresponding middleware:

app.middleware.use(SitemapMiddleware(
    isSitemap: isSitemap,
    generateURLs: generateURLs
))

And you're ready to go!

About

This package is developed and maintained by Nathan Fallet.

You might also like...
Blazing⚡️Fast BTC and ETH Wallet Generator library for React Native, Android and iOS

Blazing ⚡️ Fast BTC and ETH Wallet Generator library for React Native, Android and iOS.

Gett's Design System code generator. Use Zeplin Styleguides as your R&D's Single Source of Truth.
Gett's Design System code generator. Use Zeplin Styleguides as your R&D's Single Source of Truth.

Prism is a Design System code generator developed by the team at Gett 🚕 . Synchronizing design teams with engineering teams is a huge challenge. As t

A Quick macOS app that will check a website's sitemap.xml against a new domain
A Quick macOS app that will check a website's sitemap.xml against a new domain

Migrator Quick and dirty native macOS app that will check a website's sitemap.xml against a new domain. When you're developing your new website and wa

Vapor-telemetrydeck - Vapor client for posting signals to TelemetryDeck, a privacy-conscious analytics service for apps and websites

Vapor-telemetrydeck - Vapor client for posting signals to TelemetryDeck, a privacy-conscious analytics service for apps and websites

OpenAPI specification generator for Vapor based Swift projects.

VaporToOpenAPI VaporToOpenAPI is a Swift library which can generate output compatible with OpenAPI version 3.0.1 from Vapor code. You can use generate

🗃 Powerful and easy to use Swift Query Builder for Vapor 3.
🗃 Powerful and easy to use Swift Query Builder for Vapor 3.

⚠️ This lib is DEPRECATED ⚠️ please use SwifQL with Bridges Quick Intro struct PublicUser: Codable { var name: String var petName: String

A SwiftUI iOS App and Vapor Server to send push notifications fueled by Siri Shortcuts.
A SwiftUI iOS App and Vapor Server to send push notifications fueled by Siri Shortcuts.

Puffery An iOS App written in SwiftUI to send push notifications fueled by Siri Shortcuts. You can follow other's channels and directly receive update

Simple Application that registers Vapor Leaf's .leaf file type to LaunchServices as html enabling automatic syntax highlighting in Xcode.
Simple Application that registers Vapor Leaf's .leaf file type to LaunchServices as html enabling automatic syntax highlighting in Xcode.

Vapor Leaf Extension Update: The Vapor Leaf Extension is now meant to be used with the Xcode Plugin I designed to provide Xcode language support for t

Swift Bot with Vapor for Telegram Bot Api

Telegram Vapor Bot Please support Swift Telegram Vapor Bot Lib development by giving a ⭐️ Telegram Bot based on Swift Vapor. Swift Server Side Communi

A template Vapor app with nginx frontend.
A template Vapor app with nginx frontend.

This is an example Vapor app. It contains the app itself, as well as surrounding components (Postgres database, nginx frontend for providing secure connection), all runnable out of the box with docker compose. It is a good starting point for Vapor development of an API server which you could access from macOS and iOS clients.

VaporDocC provides middleware for use with Vapor.

VaporDocC provides middleware for use with Vapor. To initialise the middleware pass in the path to your .doccarchive, e.g.:

 🪶 Feather is a modern Swift-based content management system powered by Vapor 4.
🪶 Feather is a modern Swift-based content management system powered by Vapor 4.

Feather CMS 🪶 🪶 Feather is a modern Swift-based content management system powered by Vapor 4. 💬 Click to join the chat on Discord. Requirements To

A sample application showcasing Vapor 4 connecting to an Oracle database using SwiftOracle package.

vapor-oracle A sample application showcasing Vapor 4 connecting to an Oracle database using SwiftOracle package. In this Vapor application, we create

A dockerized microservice written in Swift using Vapor.

price-calculation-service-swift This is an example project for a university project. It uses Vapor to serve a microservice written in Swift. The point

Auto Migration generation for Vapor projects

AutoMigrator A package that generates version based migrations from Fluent.Model types. The project will check your database scheme and understand whe

A movie api created using Vapor, Fluent (ORM) and Postgres

A movie api created using Vapor, Fluent (ORM) and Postgres

Demo Vapor TIL App

Demo Vapor TIL App

A template to get vapor working on Google App Engine

Swift Vapor App Engine This is a template to get vapor working on Google App Engine. Really all that's special is that it has a Dockerfile (included w

Test project to reproduce a lockup in Vapor

Test project to reproduce a lockup in Vapor The issue was first observed when backing up the SPI database during operation. Running pg_dump would caus

Releases(1.1.0)
Owner
Vapor Community
Packages maintained by Vapor's community members.
Vapor Community
OpenAPI specification generator for Vapor based Swift projects.

VaporToOpenAPI VaporToOpenAPI is a Swift library which can generate output compatible with OpenAPI version 3.0.1 from Vapor code. You can use generate

null 3 Dec 15, 2022
A template Vapor app with nginx frontend.

This is an example Vapor app. It contains the app itself, as well as surrounding components (Postgres database, nginx frontend for providing secure connection), all runnable out of the box with docker compose. It is a good starting point for Vapor development of an API server which you could access from macOS and iOS clients.

Jaanus Kase 5 Jul 1, 2022
VaporDocC provides middleware for use with Vapor.

VaporDocC provides middleware for use with Vapor. To initialise the middleware pass in the path to your .doccarchive, e.g.:

Joseph Duffy 23 Nov 4, 2022
A movie api created using Vapor, Fluent (ORM) and Postgres

A movie api created using Vapor, Fluent (ORM) and Postgres

Vijay 0 Jan 10, 2022
Static Native Template and Dynamic Styling without any other app release

FileManager Project Students and Freshers, Good opportunity for you to learn and contribute in this project. Here you would learn how you can change t

Naveen Chauhan 3 Nov 30, 2021
Create dynamic wallpapers for macOS

Equinox Create macOS native wallpapers Description Equinox is an application that allows you to create macOS native wallpapers. Starting macOS Mojave

Dmitry Meduho 683 Jan 5, 2023
A Kotlin multiplatform library for building dynamic server-driven UI

Component Box · A Kotlin multiplatform library for building dynamic server-driven UI. Material Component-Based Interoperable Dynamic What You See Is W

Dropbox 216 Dec 31, 2022
Example how to make, update and end Live Activity. With Dynamic Island and Lock Screen.

Live Activity Example Example how to make, update and end Live Activity. With Dynamic Island and Lock Screen. Full tutorial available at sparrowcode.i

Sparrow Code 9 Dec 8, 2022
OpenAPI/Swagger 3.0 Parser and Swift code generator

SwagGen SwagGen is a library and command line tool for parsing and generating code for OpenAPI/Swagger 3.0 specs, completely written in Swift. Swagger

Yonas Kolb 568 Jan 5, 2023
The Swift code generator for your assets, storyboards, Localizable.strings, … — Get rid of all String-based APIs!

SwiftGen SwiftGen is a tool to automatically generate Swift code for resources of your projects (like images, localised strings, etc), to make them ty

null 8.3k Dec 31, 2022