Make html available in Vapor

.leaf is not syntax highlighted automatically

If you set YES to the question of whether to use Leaf when creating a new project in Vapor, `index.leaf``` will be automatically generated in Resources/Views. This .leaf``` extension is not syntax highlighted automatically in Xcode. (If you select Editor-> Syntax Coloring-> HTML, it will be applied temporarily, but if you close Xcode, it will return to the original, so you have to set it every time.) This is a hassle, so configure.swift should be able to read `` .html``` as follows.

Add import Leaf Kit and app.leaf.Change sources with sources




#### **`configure.swift`**
```swift

import Leaf
import LeafKit
import Vapor

// configures your application
public func configure(_ app: Application) throws {
    // uncomment to serve files from /Public folder
    // app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))

    app.views.use(.leaf)

    app.leaf.sources = .singleSource(NIOLeafFiles(fileio: app.fileio,
                                                    limits: .default,
                                                    sandboxDirectory: app.directory.viewsDirectory,
                                                    viewDirectory: app.directory.viewsDirectory,
                                                    defaultExtension: "html"))

    // register routes
    try routes(app)
}

index.from leaf to index.Change to html and change Syntax Coloring to HTML



 ![スクリーンショット 2020-12-21 11.46.35.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/16624/3b0b3e20-ee28-8089-f1b1-b5a44ee51e46.png)

 Now, even if you close and restart Xcode, Syntax Coloring will still be applied.



Recommended Posts

Make html available in Vapor
Make Blackjack in Java
Make jstat logs available for immediate viewing in Excel
Make exFat available on CentOS 7
Refactoring: Make Blackjack in Java
Helper methods available in devise
Make an FPS counter in Swift
all-ruby is now available in ghcr.io/ruby/all-ruby
Make multi-project executable JAR in Gradle
Make a SOAP call in C #
Make Ruby segfault in two lines