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
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) → strtext as a slug: ASCII letters and digits, lower case, words joined by -.
unique_slug(text: str, taken: list) → strA slug not in taken: slugify(text), else with -2, -3, ... after it.
transliterate(text: str) → strtext 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.qweOr with curl:
$ curl -O https://quillolang.org/plugins/files/slug.qwer$ curl -O https://quillolang.org/plugins/files/slug.qweThen, in your program, all of it or only what you call:
use slug.qweruse slugify, unique_slug from slug // Quillo 0.6: only theseIt uses these crates, which cargo fetches the first time the plugin is built:
slug = "0.1"deunicode = "1"Example
// 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
//! 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)}Related
emoji.qwer · 1.0.0Emoji for chat and comments: :shortcodes: turned into emoji and back, emoji found with their names, stripped from subjects, and searched by name for a picker.7 views · 8 downloadsJapanese kana kana.qwer · 1.0.0Japanese kana: romaji typed as hiragana or katakana, kana written in Hepburn romaji, hiragana and katakana each to the other, half-width katakana from bank and till systems made full-width, and which scripts a text uses.6 views · 10 downloadsKeywords keywords.qwer · 1.0.0The keywords and key phrases of a text by RAKE, TextRank or TF-IDF, with stop words of 58 languages left out: tags, SEO and related posts.7 views · 6 downloadsSentences sentences.qwer · 1.0.0Text split into sentences as a reader would: "Dr.", "p.m.", initials, decimals, "e.g." and quoted questions handled, with abbreviations for seven languages; positions for highlighting, and previews of whole sentences that fit a length.7 views · 9 downloadsText statistics text_stats.qwer · 1.0.0Words, sentences, syllables, reading and speaking time, Flesch reading ease and grade level of a text, for editors and writing tools.8 views · 11 downloadsUnicode unicode.qwer · 1.0.0Unicode text made comparable and measured: NFC and NFKC forms, accents removed, characters counted as people see them, safe truncation and terminal width.5 views · 8 downloadsThread 0 posts
On Slugs: questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.