From 0cfd9058e409be2080bcf74e45d74ecf72572f8b Mon Sep 17 00:00:00 2001 From: John Wiseman Date: Thu, 23 May 2019 14:50:14 -0700 Subject: [PATCH] Replaced the default slug-fn with a more robust version. The previous default slug-fn used by the slug task assumed Jekyll-style naming, e.g., "2001-01-01-my-post.md", and if this assumption was violated it would return non-sensical results. Previous slug-fn: | Source filename | Slug | Final filename | |-------------------------|---------------------|--------------------------| | "2001-01-01-my-post.md" | "my-post" | "my-post.html" | | "index.md" | "" | ".html" | | "my-great-new-post.md" | "post" | "post.html" | The new default slug-fn handles Jekyll-compliant names in the same way, but if given a filename that doesn't fit the Jekyll format it will just strip the extension. New slug-fn: | Source filename | Slug | Final filename | |-------------------------|---------------------|--------------------------| | "2001-01-01-my-post.md" | "my-post" | "my-post.html" | | "index.md" | "index" | "index.html" | | "my-great-new-post.md" | "my-great-new-post" | "my-great-new-post.html" | --- src/io/perun.clj | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/io/perun.clj b/src/io/perun.clj index 57ffde6b..9cc186df 100644 --- a/src/io/perun.clj +++ b/src/io/perun.clj @@ -717,11 +717,12 @@ (def ^:private +slug-defaults+ {; Parses `slug` portion out of the filename in the format: YYYY-MM-DD-slug-title.ext ; Jekyll uses the same format by default. - :slug-fn (fn [_ m] (->> (string/split (:filename m) #"[-\.]") - (drop 3) - drop-last - (string/join "-") - string/lower-case)) + :slug-fn (fn [_ m] + (let [f (:filename m) + matches (re-matches #"(?:[0-9]+.[0-9]+.[0-9]+.)?(.+)\..+" f)] + (if matches + (second matches) + f))) :filterer identity :extensions [".html"]})