All Projects → h4cc → Slugger

h4cc / Slugger

Licence: mit
A Slugger for elixir.

Programming Languages

elixir
2628 projects

Labels

Projects that are alternatives of or similar to Slugger

Limax
Node.js module to generate URL slugs. Another one? This one cares about i18n and transliterates non-Latin scripts to conform to the RFC3986 standard. Mostly API-compatible with similar modules.
Stars: ✭ 423 (+183.89%)
Mutual labels:  url, slug
mongoose-slug-updater
Schema-based slug plugin for Mongoose - single/compound - unique over collection/group - nested docs/arrays - relative/abs paths - sync on change: create/save/update/updateOne/updateMany/findOneAndUpdate tracked - $set operator - counter/shortId
Stars: ✭ 37 (-75.17%)
Mutual labels:  url, slug
Prestashop Clean Urls
Prestashop module. This override module allows to remove IDs from URLs
Stars: ✭ 87 (-41.61%)
Mutual labels:  url
Laravel Hashslug
Package providing a trait to use Hashids on a model
Stars: ✭ 136 (-8.72%)
Mutual labels:  slug
Finicky
A macOS app for customizing which browser to start
Stars: ✭ 2,026 (+1259.73%)
Mutual labels:  url
Urlcat
A URL builder library for JavaScript.
Stars: ✭ 1,334 (+795.3%)
Mutual labels:  url
Tinypart
TinyPart is an iOS modularization framework implemented by Ojective-C. It also supports URL-routing and inter-module communication. TinyPart是一个由Objective-C编写的面向协议的iOS模块化框架,同时它还支持URL路由和模块间通信机制。
Stars: ✭ 120 (-19.46%)
Mutual labels:  url
Urlpages
Create and view web pages stored entirely in the URL
Stars: ✭ 1,263 (+747.65%)
Mutual labels:  url
Translug
中文的 url slug 支持
Stars: ✭ 145 (-2.68%)
Mutual labels:  slug
Biturl
URL shortener service, powered by Go.
Stars: ✭ 113 (-24.16%)
Mutual labels:  url
Nova Slug Field
Slug field for Laravel Nova
Stars: ✭ 131 (-12.08%)
Mutual labels:  slug
Uddup
Urls de-duplication tool for better recon.
Stars: ✭ 103 (-30.87%)
Mutual labels:  url
Github Slug Action
GitHub Action to expose slug value of GitHub environment variables inside your GitHub workflow
Stars: ✭ 96 (-35.57%)
Mutual labels:  slug
Urltools
Elegant URL handling in R
Stars: ✭ 121 (-18.79%)
Mutual labels:  url
Use Query Params
React Hook for managing state in URL query parameters with easy serialization.
Stars: ✭ 1,278 (+757.72%)
Mutual labels:  url
Api Query Params
Convert URL query parameters to MongoDB queries
Stars: ✭ 141 (-5.37%)
Mutual labels:  url
Libvmod Querystring
Query-string module for Varnish Cache
Stars: ✭ 85 (-42.95%)
Mutual labels:  url
New Github Release Url
Generate a URL for opening a new GitHub release with prefilled tag, body, and other fields
Stars: ✭ 102 (-31.54%)
Mutual labels:  url
Url Parser
Parse URLs into nicely structured data
Stars: ✭ 118 (-20.81%)
Mutual labels:  url
Galimatias
galimatias is a URL parsing and normalization library written in Java.
Stars: ✭ 146 (-2.01%)
Mutual labels:  url

Slugger

Build Status

This package provides a library and a protocol to create slugs for given strings.

By default, a slug will be containing only chars A-Za-z0-9 and the default seperator -.

Want to use this library with Ecto? Have a look at sobolevn/ecto_autoslug_field.

Installation

Add slugger to your list of dependencies in mix.exs:

def deps do
  [
    {:slugger, "~> 0.3"},
  ]
end

Configuration

The following options can be set in your config.exs and will be used at next compile!

# Char used as separator between words.
config :slugger, separator_char: ?-

# Path to the file containing replacements.
config :slugger, replacement_file: "lib/replacements.exs"

Library

Using the library is straightforward, check out a few examples:

iex(1)> Slugger.slugify " A b C "
"A-b-C"

iex(2)> Slugger.slugify_downcase " A b C "
"a-b-c"

iex(3)> Slugger.slugify "A cool title of a blog post"
"A-cool-title-of-a-blog-post"

iex(4)> Slugger.slugify_downcase("Kluski Śląskie @ Jalapeño Bilingüe")
"kluski-slaskie-at-jalapeno-bilinguee"

iex(5)> Slugger.slugify "Wikipedia Style", ?_
"Wikipedia_Style"

iex(6)> Slugger.truncate_slug "A-to-long-slug-that-should-be-truncated", 16
"A-to-long-slug"

Protocol

Next to the library, a protocol is provided to ease creating slugs for own data structures. By default, the protocol will try to run Slugger.slugify(Kernel.to_string(your_data)), so if your_data implements String.Chars, the returned string will be slugified. If you want to provide your own way to create a slug, check out the following example:

iex(10)> defmodule User do
...(10)>   defstruct name: "Julius Beckmann"
...(10)> end

iex(11)> defimpl Slugify, for: User do   
...(11)>   def slugify(user), do: Slugger.slugify(user.name)
...(11)> end

iex(12)> Slugify.slugify %User{}                          
"Julius-Beckmann"

Replacements

Special chars like äöüéáÁÉ will be replaced by rules given in the file lib/replacements.exs.

Copy that file if you need have own replacement rules, change the config value and recompile.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].