Renames slug field to alias

This commit is contained in:
Stavros Polymenis 2017-06-04 15:24:50 +01:00
parent a39ee71b46
commit 403d9ebaed
7 changed files with 18 additions and 18 deletions

View File

@ -18,7 +18,7 @@ let opt_element tag_name content body =
let entry config url node_fn note = let entry config url node_fn note =
let open Logarion in let open Logarion in
let meta = note.Note.meta in let meta = note.Note.meta in
let u = "note/" ^ Meta.slug meta in let u = "note/" ^ Meta.alias meta in
let open Meta in let open Meta in
let open Author in let open Author in
("<entry>" ("<entry>"

View File

@ -58,7 +58,7 @@ let note_with_alias store alias =
|> Array.to_list |> Array.to_list
|> List.filter (fun file -> BatString.ends_with file Lpath.extension) |> List.filter (fun file -> BatString.ends_with file Lpath.extension)
|> List.fold_left cons_valid_meta [] |> List.fold_left cons_valid_meta []
|> List.filter (fun note -> Meta.slug note.Note.meta = alias) |> List.filter (fun note -> Meta.alias note.Note.meta = alias)
|> List.fast_sort (fun a b -> recency_order a.Note.meta b.Note.meta) |> List.fast_sort (fun a b -> recency_order a.Note.meta b.Note.meta)
in in
try Some (List.hd notes) try Some (List.hd notes)

View File

@ -42,7 +42,7 @@ let of_note ?(header_tpl=None) ?(note_tpl=None) blog_url lgrn ymd =
let article_link meta = let article_link meta =
let open Logarion in let open Logarion in
let u = "/note/" ^ Meta.slug meta in let u = "/note/" ^ Meta.alias meta in
let d = let d =
let open Meta in let open Meta in
Unsafe.data Note.(meta.Meta.title ^ (Meta.Date.pretty_date (meta.date |> Meta.Date.last))) Unsafe.data Note.(meta.Meta.title ^ (Meta.Date.pretty_date (meta.date |> Meta.Date.last)))

View File

@ -1,5 +1,5 @@
module Id = Meta.Id module Id = Meta.Id
type slug_t = string type alias_t = string
module Configuration = struct module Configuration = struct
type t = { type t = {
@ -35,7 +35,7 @@ module Configuration = struct
} }
end end
module SlugMap = Meta.SlugMap module AliasMap = Meta.AliasMap
module Make (Store : Store.T) = struct module Make (Store : Store.T) = struct
type t = { type t = {

View File

@ -36,12 +36,12 @@ let fpath_of_note = function Note n -> (fpath_of_repo n.repo // notes // n.basen
let string_of_note n = fpath_of_note n |> to_string let string_of_note n = fpath_of_note n |> to_string
let note_of_basename repo s = Note { repo; basename = v s } let note_of_basename repo s = Note { repo; basename = v s }
let slug_of_note = function Note n -> n.basename |> rem_ext |> to_string let alias_of_note = function Note n -> n.basename |> rem_ext |> to_string
let note_of_slug repo slug = note_of_basename repo (slug ^ extension) let note_of_alias repo alias = note_of_basename repo (alias ^ extension)
let versioned_basename_of_title ?(version=0) repo (title : string) = let versioned_basename_of_title ?(version=0) repo (title : string) =
let notes_fpath = fpath_of_repo repo // notes in let notes_fpath = fpath_of_repo repo // notes in
let basename = v @@ Meta.string_slug title in let basename = v @@ Meta.string_alias title in
let rec next version = let rec next version =
let candidate = basename |> add_ext (string_of_int version) |> add_ext extension in let candidate = basename |> add_ext (string_of_int version) |> add_ext extension in
if Sys.file_exists (to_string (notes_fpath // candidate)) if Sys.file_exists (to_string (notes_fpath // candidate))

View File

@ -86,7 +86,7 @@ let stringset_csv set =
let f elt a = if a <> "" then a ^ ", " ^ elt else elt in let f elt a = if a <> "" then a ^ ", " ^ elt else elt in
StringSet.fold f set "" StringSet.fold f set ""
let string_slug t = let string_alias t =
let is_reserved = function let is_reserved = function
| '!' | '*' | '\'' | '(' | ')' | ';' | ':' | '@' | '&' | '=' | '+' | '$' | '!' | '*' | '\'' | '(' | ')' | ';' | ':' | '@' | '&' | '=' | '+' | '$'
| ',' | '/' | '?' | '#' | '[' | ']' | ' ' | '\t' | '\x00' -> true | ',' | '/' | '?' | '#' | '[' | ']' | ' ' | '\t' | '\x00' -> true
@ -111,7 +111,7 @@ type t = {
series: StringSet.t; series: StringSet.t;
abstract: string; abstract: string;
uuid: Id.t; uuid: Id.t;
slug: string; alias: string;
} [@@deriving lens { submodule = true }] } [@@deriving lens { submodule = true }]
let blank ?(uuid=(Id.generate ())) () = { let blank ?(uuid=(Id.generate ())) () = {
@ -124,17 +124,17 @@ let blank ?(uuid=(Id.generate ())) () = {
series = StringSet.empty; series = StringSet.empty;
abstract = ""; abstract = "";
uuid; uuid;
slug = ""; alias = "";
} }
let listed e = CategorySet.listed e.categories let listed e = CategorySet.listed e.categories
let published e = CategorySet.published e.categories let published e = CategorySet.published e.categories
let unique_topics ts x = StringSet.union ts x.topics let unique_topics ts x = StringSet.union ts x.topics
module SlugMap = Map.Make(String) module AliasMap = Map.Make(String)
module IdMap = Map.Make(Id) module IdMap = Map.Make(Id)
let slug meta = if meta.slug = "" then string_slug meta.title else meta.slug let alias meta = if meta.alias = "" then string_alias meta.title else meta.alias
let value_with_name (meta as m) = function let value_with_name (meta as m) = function
| "title" -> m.title | "title" -> m.title
@ -151,7 +151,7 @@ let value_with_name (meta as m) = function
| "keywords" -> stringset_csv m.keywords; | "keywords" -> stringset_csv m.keywords;
| "series" -> stringset_csv m.series; | "series" -> stringset_csv m.series;
| "uuid" -> Id.to_string m.uuid | "uuid" -> Id.to_string m.uuid
| "slug" -> slug m | "alias" -> alias m
| e -> invalid_arg e | e -> invalid_arg e
let with_kv meta (k,v) = let with_kv meta (k,v) =
@ -178,7 +178,7 @@ let with_kv meta (k,v) =
| "series" -> { meta with series = trim v |> list_of_csv |> StringSet.of_list } | "series" -> { meta with series = trim v |> list_of_csv |> StringSet.of_list }
| "uuid" -> | "uuid" ->
(match Id.of_string v with Some id -> (uuid ^= id) meta | None -> meta) (match Id.of_string v with Some id -> (uuid ^= id) meta | None -> meta)
| "slug" -> { meta with slug = v } | "alias" -> { meta with alias = v }
| _ -> meta | _ -> meta
let to_string (meta as m) = let to_string (meta as m) =
@ -208,7 +208,7 @@ let to_string (meta as m) =
s "series" (stringset_csv m.series); s "series" (stringset_csv m.series);
s "abstract" m.abstract; s "abstract" m.abstract;
s "uuid" (Uuidm.to_string m.uuid); s "uuid" (Uuidm.to_string m.uuid);
s "slug" m.slug s "alias" m.alias
] ]
in in
String.concat "" rows String.concat "" rows

View File

@ -72,7 +72,7 @@ let fold_note ymd =
let fold_meta (meta : Meta.t) = let fold_meta (meta : Meta.t) =
let open Logarion in let open Logarion in
let escaped e = match e with let escaped e = match e with
| "url" -> "/note/" ^ Meta.slug meta | "url" -> "/note/" ^ Meta.alias meta
| "date" | "date_created" | "date_edited" | "date_published" | "date_human" -> | "date" | "date_created" | "date_edited" | "date_published" | "date_human" ->
"<time>" ^ Meta.value_with_name meta e ^ "</time>" "<time>" ^ Meta.value_with_name meta e ^ "</time>"
| tag -> Meta.value_with_name meta tag in | tag -> Meta.value_with_name meta tag in
@ -87,7 +87,7 @@ let fold_header blog_url title =
let fold_list ?(item_tpl=None) ~from ~n notes = let fold_list ?(item_tpl=None) ~from ~n notes =
let simple meta = let simple meta =
"<li><a href=\"/note/" ^ Meta.slug meta ^ "\">" "<li><a href=\"/note/" ^ Meta.alias meta ^ "\">"
^ meta.Meta.title ^ " ~ " ^ Meta.Date.(pretty_date (last meta.Meta.date)) ^ meta.Meta.title ^ " ~ " ^ Meta.Date.(pretty_date (last meta.Meta.date))
^ "</a></li>" ^ "</a></li>"
in in