Sunday, March 26, 2023
Learning Code
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#
No Result
View All Result
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#
No Result
View All Result
Learning Code
No Result
View All Result
Home Swift

Content filters in Feather CMS

learningcode_x1mckf by learningcode_x1mckf
September 20, 2022
in Swift
0
Content filters in Feather CMS
74
SHARES
1.2k
VIEWS
Share on FacebookShare on Twitter


2020/08/12

On this article I will inform you all about content material filters and present you how you can construct your personal one utilizing hooks features and Vapor.

Vapor

The anatomy of a content material filter

If you create a weblog publish or a static web page in Feather you should use the markdown filter to render the ultimate illustration of the saved content material. It’s also doable to focus on Swift code snippets although one other filter. These content material filters are altering the underlying information in dynamic approach at runtime, Feather solely saves the unique information within the persistent srorage utilizing Fluent. 💪

This strategy permits us to rework numerous textual content values utilizing manually chosen filters for every particular person frontend associated content material. For instance you possibly can allow the markdown filter for publish A, however in case you want to make use of HTML for publish B you possibly can disable the markdown filter and write your article utilizing the nice previous HyperText Markup Language.

Content material filters can be utilized to create your personal shortcodes. In WordPress shortcode is a small piece of code, indicated by brackets, that may carry out a devoted perform. Through the use of Feather you do not have to place shortcodes into brackets, however you possibly can change something you need based mostly by yourself guidelines. Curse phrases? No downside. Print one thing utilizing Swift? Why not.

The one factor that you need to remember that content material filters are operating in a synchronous approach. Be as quick as doable, since they’ll block the execution thread. In a lot of the circumstances this isn’t a giant deal, however I simply wished to let you already know that you just will not be capable of return a future this time. 🚀



How you can create a content material filter for Feather?

Content material filters are supplied by modules, which means that you need to write a Feather CMS module first. Don’t be concerned an excessive amount of, a module might be fairly easy, in our case it is simply going to be one Swift file. We’re going to write a filter that is going to switch the fuck phrase with a duck emoji. 🦆

import Vapor
import Fluent
import ViperKit

last class DuckFilterModule: ViperModule 

    static var identify: String = "duck-filter"

    func invokeSync(identify: String, req: Request, params: [String: Any]) -> Any? 
        swap identify 
        case "content-filter":
            return [DuckFilter()]
        default:
            return nil
        
    

Simply place the code from above into a brand new file known as DuckFilterModule.swift contained in the Modules listing. We now have to present the module a reputation, that is going to be duck-filter after all, and now we have to implement the invokeSync hook perform that ought to return a filter sort for the content-filter key. You may even return a number of filters per module if wanted.

Hook features are fairly important in Feather CMS, modules can work together through dynamic hooks with out forming a dependency. This strategy may be very versatile and highly effective, you possibly can construct and invoke your personal hooks by means of the ViperKit framework. If you wish to study extra about this modular structure, you may also grab a copy of my Practical Server Side Swift book, it is written for Vapor 4 and you may discover ways to write a modular weblog engine utilizing Swift (similiar to Feather).

Anyway, again to the subject, we simply need to implement the DuckFilter object:

import Vapor
import ViperKit

struct DuckFilter: ContentFilter 
    var key: String  "duck-filter" 
    var label: String  "Duck" 

    func filter(_ enter: String) -> String 
        enter.replacingOccurrences(of: "fuck", with: "🦆")
    

Principally that is it. You simply have to change the configure.swift and append a DuckFilterModule() occasion to the module checklist. Now in case you run Feather with this module you possibly can allow the Duck filter in your contents below the content material editor admin interface. Oh by the best way it can save you this filter below a ContentFilters/DuckFilter.swift listing subsequent to your module file.



How you can invoke out there filters?

Let’s check out our newly created filter. Go to the admin and create a brand new static web page with the “I do not give a fuck” content material, nicely… it may be something that incorporates the f phrase, simply be artistic. 🤔



You might also like

Introducing – AI Utils for macOS

Encoding and decoding data using the Hummingbird framework

Hummingbird routing and requests – The.Swift.Dev.

Save the web page and preview it utilizing the attention icon. It is best to see your unique textual content. Now in case you click on on the feather icon you possibly can choose which filters must be enabled for this explicit content material. Verify the Duck, save the content material particulars and reload the preview web page. It is best to see the duckling. 🐥

These content material filters are programmatically out there for you. By calling the filter methodology on any FrontendContentModel sort you possibly can invoke the enabled filters on that content material, this may help you rework an related mannequin worth utilizing filters.

let filteredValue = frontendContentModel.filter(myModel.contentToBeFiltered, req: req)

The one catch is that your Fluent mannequin must have an related content material sort since filters are tied to FrontendContentModel objects. In my previous article I discussed how you can create a content material relation, however perhaps subsequent time I will create an extended publish in regards to the existence of this particular object in Feather CMS. You probably have points, feedbacks or concepts, please use GitHub or Twitter.






Source link

Share30Tweet19
learningcode_x1mckf

learningcode_x1mckf

Recommended For You

Introducing – AI Utils for macOS

by learningcode_x1mckf
March 24, 2023
0
Introducing – AI Utils for macOS

⚠️ REQUIRES a FREE OpenAI API key. You will get one utilizing this hyperlink. ⚠️ Improve your productiveness with our AI powered utility application. - accessible...

Read more

Encoding and decoding data using the Hummingbird framework

by learningcode_x1mckf
March 22, 2023
0
Encoding and decoding data using the Hummingbird framework

HTTP is all about sending and receiving information over the community. Initially it was solely utilized to switch HTML paperwork, however these days we use HTTP to switch...

Read more

Hummingbird routing and requests – The.Swift.Dev.

by learningcode_x1mckf
March 17, 2023
0
Hummingbird routing and requests – The.Swift.Dev.

Routing on the server facet means the server goes to ship a response primarily based on the URL path that the consumer referred to as when firing up...

Read more

Building a Scrollable Custom Tab Bar in SwiftUI

by learningcode_x1mckf
March 10, 2023
0
Building a Scrollable Custom Tab Bar in SwiftUI

Whether or not you’re making a social media app or a productiveness device, the tab bar interface can improve the consumer expertise by making it extra intuitive and...

Read more

Beginner’s guide to server-side Swift using the Hummingbird framework

by learningcode_x1mckf
March 8, 2023
0
Beginner’s guide to server-side Swift using the Hummingbird framework

Swift on the Server in 2023 Three years in the past I began to focus on Vapor, the preferred web-framework written in Swift, which served me very...

Read more
Next Post
Get ‘JavaScript from Beginner to Professional’ ($28.99 value) FREE for a limited time

Get 'JavaScript from Beginner to Professional' ($28.99 value) FREE for a limited time

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related News

Promises in JavaScript: A Primer

Promises in JavaScript: A Primer

November 25, 2022
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

Central Java, Norway explore energy transition cooperation – ANTARA English

February 16, 2023
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

Meet Zig: The modern alternative to C – InfoWorld

March 10, 2023

Browse by Category

  • C#
  • C++
  • Java
  • JavaScript
  • Python
  • Swift

RECENT POSTS

  • 2023 Java roadmap for developers – TheServerSide.com
  • YS Jagan launches Ragi Java in Jagananna Gorumudda, says focused on intellectual development of students – The Hans India
  • Disadvantages of Java – TheServerSide.com

CATEGORIES

  • C#
  • C++
  • Java
  • JavaScript
  • Python
  • Swift

© 2022 Copyright Learning Code

No Result
View All Result
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#

© 2022 Copyright Learning Code

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?