Text

Slugs

Slugs for addresses from titles in any script, unique ones for a blog, and text transliterated to ASCII.

Version 1.0.0 · 3 functions · 2 crates

#urls#seo#unicode#text

Functions

What use slug.qwer gives a program, with the types Quillo sees. To take only some, or under other names: use slugify, unique_slug from slug (Quillo 0.6).

slugify(text: str) → str

text as a slug: ASCII letters and digits, lower case, words joined by -.

unique_slug(text: str, taken: list) → str

A slug not in taken: slugify(text), else with -2, -3, ... after it.

transliterate(text: str) → str

text in plain ASCII, accents and other scripts written in Latin letters, case and spaces kept.

Get it

$ quillo install slug               # slug.qwer into this folder$ quillo install slug --example     # and its example, slug.qwe

Or with curl:

$ curl -O https://quillolang.org/plugins/files/slug.qwer$ curl -O https://quillolang.org/plugins/files/slug.qwe

Then, in your program, all of it or only what you call:

main.qwe
use slug.qweruse slugify, unique_slug from slug      // Quillo 0.6: only these

It uses these crates, which cargo fetches the first time the plugin is built:

[dependencies]
slug = "0.1"deunicode = "1"

Example

slug.qwe
// Addresses for posts, unique in the blog.////   quillo run slug.qwe      then open http://localhost:8080/slugsuse "slug.qwer"route GET /slugs = {    plain: slugify("Crème brûlée à Paris!"),    tokyo: slugify("東京 2026"),    unique: unique_slug("Hello World", ["hello-world", "hello-world-2"]),    ascii: transliterate("Zoë Saldaña"),}
$ quillo run slug.qwe$ curl 'localhost:8080/slugs'

Source

slug.qwer
//! Slugs for addresses from any title, any script: "Crème brûlée à Paris" is "creme-brulee-a-paris", "東京" is "dong-jing".//! version: 1.0.0//!//! [dependencies]//! slug = "0.1"//! deunicode = "1"/// `text` as a slug: ASCII letters and digits, lower case, words joined by `-`.pub fn slugify(text: &str) -> String {    slug::slugify(text)}/// A slug not in `taken`: `slugify(text)`, else with `-2`, `-3`, ... after it.pub fn unique_slug(text: &str, taken: Vec<String>) -> String {    let base = slug::slugify(text);    let base = if base.is_empty() { "item".to_string() } else { base };    if !taken.contains(&base) {        return base;    }    (2..).map(|n| format!("{}-{}", base, n)).find(|s| !taken.contains(s)).unwrap()}/// `text` in plain ASCII, accents and other scripts written in Latin letters, case and spaces kept.pub fn transliterate(text: &str) -> String {    deunicode::deunicode(text)}
Thread
78Useful? Like it, or add to its thread below.

Thread 0 posts

On Slugs: questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.