package slug

  1. Overview
  2. Docs
Url safe slug generator

Install

Dune Dependency

Authors

Maintainers

Sources

1.0.0.tar.gz
sha256=5416ac84c16436657852c2ef070c77b083e8a443497585e278e5f5e019f952d7
md5=85a2ca8ddd75b97de98f103b5b250feb

Description

A URL slug is the part of a URL or link that comes after the domain extension.

In websites the keyword used for your URL slug can be used to SEO optimize the URL by showing Google the structure of your site and the contents of the page in question.

Published: 07 Jul 2021

README

ocaml-slug

Url safe slug generator for OCaml

This library uses algorithm and data from node-slugify

Installation

opam install slug

If you use esy

esy add @opam/slug

Usage

  • OCaml syntax:

Slug.slugify "my string";;
- : string = "my-string"

(* Custom separator *)
Slug.slugify ?sep: "_" "my string";;
- : string = "my_string" 

(* Retain uppercase *)
Slug.slugify ?lowercase: false "My String";;
- : string = "My-String" 

(* Use locale *)
let with_vi = Slug.(Charmap.mk_charmap [Slug_data.base; Slug_data.vi]);;
- : Charmap.t = <abstr>
Slug.slugify ?charmap: with_vi "Đ";;
- : string = "d" 
Slug.slugify "Đ";;
- : string = "dj"

(* Custom characters map *)
let custom_map = Slug.(Charmap.mk_charmap [Slug_data.base; [ ("M", "z"); ("m", "z") ]]);;
val custom_map : Charmap.t = <abstr>

Slug.slugify ?charmap: custom_map "Mm";;
- : string = "zz"
  • ReasonML syntax

Slug.slugify("my string");
- : string = "my-string"

/* Custom separator */
Slug.slugify(~sep = "_", "my string");
- : string = "my_string" 

/* Retain uppercase */
Slug.slugify(~lowercase = false, "My String");
- : string = "My-String" 

/* Use locale */
let with_vi = Slug.(Charmap.mk_charmap([Slug_data.base, Slug_data.vi]));
let with_vi : Charmap.t = <abstr>
Slug.slugify(~charmap = with_vi, "Đ");
- : string = "d" 
Slug.slugify("Đ");
- : string = "dj"

/* Custom characters map */
let custom_map = Slug.(Charmap.mk_charmap([Slug_data.base, [ ("M", "z"), ("m", "z") ]]));;
let custom_map : Charmap.t = <abstr>

Slug.slugify(~charmap = custom_map, "Mm");
- : string = "zz"

Notice

Please don't send PR to update data/*. They are auto-generated from upstream library.

Please send PRs about new locales to node-slugify.

If you really need it, you can use a custom_map instead.

License

MIT. Data are downloaded from node-slugify

Dependencies (6)

  1. re >= "1.7.2"
  2. uutf
  3. uuseg
  4. uunf >= "1.0.0"
  5. dune >= "2.0"
  6. ocaml >= "4.05"

Dev Dependencies (3)

  1. alcotest with-test
  2. yojson dev
  3. opam-lock dev

Used by (1)

  1. camyll >= "0.4.0"

Conflicts

None

OCaml

Innovation. Community. Security.