Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lag en hyggelig URL til alle matvarene
Co-authored-by: Magnar Sveen <magnar.sveen@mattilsynet.no>
- Loading branch information
Showing
4 changed files
with
46 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
(ns matvaretabellen.urls | ||
(:require [clojure.string :as str]) | ||
#?(:clj (:import (java.text Normalizer)))) | ||
|
||
(defn remove-diacritics [s] | ||
(-> #?(:clj (Normalizer/normalize s java.text.Normalizer$Form/NFD) | ||
:cljs (.normalize s "NFD")) | ||
(str/replace #"[\u0300-\u036F]" "") | ||
(str/replace #"æ" "ae") | ||
(str/replace #"ø" "o"))) | ||
|
||
(defn slugify [s] | ||
(-> (str/lower-case s) | ||
remove-diacritics | ||
(str/replace #"\W+" "-"))) | ||
|
||
(defn get-url [locale food-name] | ||
(str (when-not (= :nb locale) | ||
(str "/" (name locale))) | ||
"/" (slugify food-name) "/")) | ||
|
||
(comment | ||
|
||
(slugify "Müsli og grøt fra ørten 5gr D12 vitamin kål") | ||
|
||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters