PardallMarkdown.Content.Utils (PardallMarkdown v0.4.4) View Source

Link to this section Summary

Functions

Convert map string keys to :atom keys

Transforms a source string into a taxonomy title.

Transforms a source string into a post title.

Splits a path into a tree of categories, containing both readable category names and slugs for all categories in the hierarchy. The categories list is indexed from the topmost to the lowermost in the hiearchy, example: Games > PC > RPG.

Examples

iex> PardallMarkdown.Content.Utils.extract_slug_from_path("/blog/art/3d/post.md")
"/blog/art/3d/post"

iex> PardallMarkdown.Content.Utils.extract_slug_from_path("/blog/My new Project.md")
"/blog/my-new-project"

iex> PardallMarkdown.Content.Utils.extract_slug_from_path("/blog/_index.md")
"/blog/-index"

Transforms a file name from a path into a readable post title.

Link to this section Functions

Convert map string keys to :atom keys

Link to this function

capitalize_as_taxonomy_name(source)

View Source

Transforms a source string into a taxonomy title.

Examples

iex> PardallMarkdown.Content.Utils.capitalize_as_taxonomy_name("post-about-art")
"Post About Art"

iex> PardallMarkdown.Content.Utils.capitalize_as_taxonomy_name("3d-models")
"3D Models"

iex> PardallMarkdown.Content.Utils.capitalize_as_taxonomy_name("Products: wood-chairs")
"Products: Wood Chairs"

iex> PardallMarkdown.Content.Utils.capitalize_as_taxonomy_name("products-above-$300mm")
"Products Above $300MM"
Link to this function

capitalize_as_title(source)

View Source

Transforms a source string into a post title.

Examples

iex> PardallMarkdown.Content.Utils.capitalize_as_title("post-about-art")
"Post about art"

iex> PardallMarkdown.Content.Utils.capitalize_as_title("My new Project")
"My new Project"

iex> PardallMarkdown.Content.Utils.capitalize_as_title("2d 3D 4d-art: this is bugged, 3d should've been preserved as 3d not separate strings")
"2d 3D 4d art: this is bugged, 3d should've been preserved as 3d not separate strings"

iex> PardallMarkdown.Content.Utils.capitalize_as_title("Some Startup plans to expand quantum Platform of the Platforms with $500M investment")
"Some Startup plans to expand quantum Platform of the Platforms with $500M investment"
Link to this function

extract_categories_from_path(full_path)

View Source

Splits a path into a tree of categories, containing both readable category names and slugs for all categories in the hierarchy. The categories list is indexed from the topmost to the lowermost in the hiearchy, example: Games > PC > RPG.

Also returns the level in the tree in which the category can be found, as well as all parent categories slugs recursively, where level: 0 is for root pages (i.e. no category).

TODO: For the initial purpose of this project, this solution is ok, but eventually let's implement it with a "real" tree or linked list.

Examples

iex> PardallMarkdown.Content.Utils.extract_categories_from_path("/blog/art/3d-models/post.md")
[
  %{title: "Blog", slug: "/blog", level: 0, parents: ["/"]},
  %{
    title: "Art",
    slug: "/blog/art",
    level: 1,
    parents: ["/", "/blog"]
  },
  %{
    title: "3D Models",
    slug: "/blog/art/3d-models",
    level: 2,
    parents: ["/", "/blog", "/blog/art"]
  }
]

iex> PardallMarkdown.Content.Utils.extract_categories_from_path("/blog/post.md")
[%{title: "Blog", slug: "/blog", level: 0, parents: ["/"]}]

iex> PardallMarkdown.Content.Utils.extract_categories_from_path("/post.md")
[%{title: "Home", slug: "/", level: 0, parents: ["/"]}]

iex> PardallMarkdown.Content.Utils.extract_categories_from_path("./test/relative/path/some-post.md")
[
  %{level: 0, parents: ["/"], slug: "/test", title: "Test"},
  %{level: 1, parents: ["/", "/test"], slug: "/test/relative", title: "Relative"},
  %{level: 2, parents: ["/", "/test", "/test/relative"], slug: "/test/relative/path", title: "Path"}
]

iex> PardallMarkdown.Content.Utils.extract_categories_from_path("test/relative/no_slash.md")
[
  %{level: 0, parents: ["/"], slug: "/test", title: "Test"},
  %{level: 1, parents: ["/", "/test"], slug: "/test/relative", title: "Relative"}
]

iex> PardallMarkdown.Content.Utils.extract_categories_from_path("../../test/relative/path/some-post.md")
[
  %{level: 0, parents: ["/"], slug: "/test", title: "Test"},
  %{level: 1, parents: ["/", "/test"], slug: "/test/relative", title: "Relative"},
  %{level: 2, parents: ["/", "/test", "/test/relative"], slug: "/test/relative/path", title: "Path"}
]
Link to this function

extract_slug_from_path(path)

View Source

Examples

iex> PardallMarkdown.Content.Utils.extract_slug_from_path("/blog/art/3d/post.md")
"/blog/art/3d/post"

iex> PardallMarkdown.Content.Utils.extract_slug_from_path("/blog/My new Project.md")
"/blog/my-new-project"

iex> PardallMarkdown.Content.Utils.extract_slug_from_path("/blog/_index.md")
"/blog/-index"
Link to this function

extract_title_from_path(path)

View Source

Transforms a file name from a path into a readable post title.

Examples

iex> PardallMarkdown.Content.Utils.extract_title_from_path("/blog/art/3d/post-about-art.md")
"Post about art"

iex> PardallMarkdown.Content.Utils.extract_title_from_path("/blog/My new Project.md")
"My new Project"
Link to this function

is_content_draft_by_default?()

View Source
Link to this function

is_path_from_static_assets?(path)

View Source
Link to this function

remote_repository_local_path()

View Source
Link to this function

slugify(value, ignore \\ ["/"])

View Source