Remove multi author mode
This commit is contained in:
parent
223e886102
commit
4f0efc8fb7
10 changed files with 5 additions and 186 deletions
|
@ -32,10 +32,6 @@ config :mebe_2,
|
||||||
blog_author: "Author McAuthor",
|
blog_author: "Author McAuthor",
|
||||||
# Absolute URL to the site, including protocol, no trailing slash
|
# Absolute URL to the site, including protocol, no trailing slash
|
||||||
absolute_url: "http://localhost:2124",
|
absolute_url: "http://localhost:2124",
|
||||||
# Set to true to show author header from posts, if available (blog_author will be used as default)
|
|
||||||
multi_author_mode: false,
|
|
||||||
# If multi author mode is on, use blog_author as default author (if this is false, no author will be set if post has no author header)
|
|
||||||
use_default_author: true,
|
|
||||||
# Default timezone to use for posts with time data
|
# Default timezone to use for posts with time data
|
||||||
time_default_tz: "Europe/Helsinki",
|
time_default_tz: "Europe/Helsinki",
|
||||||
# Force "Read more…" text to display even if there is no more content
|
# Force "Read more…" text to display even if there is no more content
|
||||||
|
|
|
@ -5,7 +5,7 @@ defmodule Mebe2.Engine.Crawler do
|
||||||
"""
|
"""
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
alias Mebe2.Engine.{Parser, Utils, SlugUtils}
|
alias Mebe2.Engine.Parser
|
||||||
alias Mebe2.Engine.Models.{Page, Post}
|
alias Mebe2.Engine.Models.{Page, Post}
|
||||||
|
|
||||||
def crawl(path) do
|
def crawl(path) do
|
||||||
|
@ -51,9 +51,7 @@ defmodule Mebe2.Engine.Crawler do
|
||||||
posts: [],
|
posts: [],
|
||||||
years: %{},
|
years: %{},
|
||||||
months: %{},
|
months: %{},
|
||||||
tags: %{},
|
tags: %{}
|
||||||
authors: %{},
|
|
||||||
author_names: %{}
|
|
||||||
},
|
},
|
||||||
fn pagedata, acc ->
|
fn pagedata, acc ->
|
||||||
case pagedata do
|
case pagedata do
|
||||||
|
@ -73,8 +71,6 @@ defmodule Mebe2.Engine.Crawler do
|
||||||
Map.put(tagmap, tag, [pagedata | posts])
|
Map.put(tagmap, tag, [pagedata | posts])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
{authors, author_names} = form_authors(acc, pagedata)
|
|
||||||
|
|
||||||
year_posts = [pagedata | Map.get(acc.years, year, [])]
|
year_posts = [pagedata | Map.get(acc.years, year, [])]
|
||||||
month_posts = [pagedata | Map.get(acc.months, {year, month}, [])]
|
month_posts = [pagedata | Map.get(acc.months, {year, month}, [])]
|
||||||
|
|
||||||
|
@ -83,31 +79,10 @@ defmodule Mebe2.Engine.Crawler do
|
||||||
| posts: [pagedata | acc.posts],
|
| posts: [pagedata | acc.posts],
|
||||||
years: Map.put(acc.years, year, year_posts),
|
years: Map.put(acc.years, year, year_posts),
|
||||||
months: Map.put(acc.months, {year, month}, month_posts),
|
months: Map.put(acc.months, {year, month}, month_posts),
|
||||||
tags: tags,
|
tags: tags
|
||||||
authors: authors,
|
|
||||||
author_names: author_names
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp form_authors(datalist, pagedata) do
|
|
||||||
multi_author_mode = Mebe2.get_conf(:multi_author_mode)
|
|
||||||
do_form_authors(multi_author_mode, datalist, pagedata)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp do_form_authors(false, _, _), do: {%{}, %{}}
|
|
||||||
|
|
||||||
defp do_form_authors(true, %{authors: authors, author_names: author_names}, pagedata) do
|
|
||||||
author_name = Utils.get_author(pagedata)
|
|
||||||
author_slug = SlugUtils.slugify(author_name)
|
|
||||||
author_posts = [pagedata | Map.get(authors, author_slug, [])]
|
|
||||||
authors = Map.put(authors, author_slug, author_posts)
|
|
||||||
|
|
||||||
# Authors end up with the name that was in the post with the first matching slug
|
|
||||||
author_names = Map.put_new(author_names, author_slug, author_name)
|
|
||||||
|
|
||||||
{authors, author_names}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
defmodule Mebe2.Engine.DB do
|
defmodule Mebe2.Engine.DB do
|
||||||
require Logger
|
require Logger
|
||||||
import Ex2ms
|
import Ex2ms
|
||||||
alias Mebe2.Engine.{Utils, SlugUtils, Models}
|
alias Mebe2.Engine.Models
|
||||||
|
|
||||||
alias Calendar.DateTime
|
alias Calendar.DateTime
|
||||||
|
|
||||||
|
@ -25,9 +25,6 @@ defmodule Mebe2.Engine.DB do
|
||||||
# Table for storing posts with tag as first element of key
|
# Table for storing posts with tag as first element of key
|
||||||
@tag_table :mebe2_tags
|
@tag_table :mebe2_tags
|
||||||
|
|
||||||
# Table for storing posts by specific authors
|
|
||||||
@author_table :mebe2_authors
|
|
||||||
|
|
||||||
# Table for storing menu data
|
# Table for storing menu data
|
||||||
@menu_table :mebe2_menu
|
@menu_table :mebe2_menu
|
||||||
|
|
||||||
|
@ -41,10 +38,6 @@ defmodule Mebe2.Engine.DB do
|
||||||
:ets.new(@single_post_table, [:named_table, :set, :protected, read_concurrency: true])
|
:ets.new(@single_post_table, [:named_table, :set, :protected, read_concurrency: true])
|
||||||
:ets.new(@tag_table, [:named_table, :ordered_set, :protected, read_concurrency: true])
|
:ets.new(@tag_table, [:named_table, :ordered_set, :protected, read_concurrency: true])
|
||||||
:ets.new(@menu_table, [:named_table, :ordered_set, :protected, read_concurrency: true])
|
:ets.new(@menu_table, [:named_table, :ordered_set, :protected, read_concurrency: true])
|
||||||
|
|
||||||
if Mebe2.get_conf(:multi_author_mode) do
|
|
||||||
:ets.new(@author_table, [:named_table, :ordered_set, :protected, read_concurrency: true])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
|
@ -93,20 +86,6 @@ defmodule Mebe2.Engine.DB do
|
||||||
|
|
||||||
:ets.insert(@post_table, ordered_posts)
|
:ets.insert(@post_table, ordered_posts)
|
||||||
:ets.insert(@single_post_table, single_posts)
|
:ets.insert(@single_post_table, single_posts)
|
||||||
|
|
||||||
if Mebe2.get_conf(:multi_author_mode) do
|
|
||||||
author_posts =
|
|
||||||
Enum.filter(posts, fn post -> Map.has_key?(post.extra_headers, "author") end)
|
|
||||||
|> Enum.map(fn post ->
|
|
||||||
{{year, month, day}, _} = DateTime.to_erl(post.datetime)
|
|
||||||
|
|
||||||
author_slug = Utils.get_author(post) |> SlugUtils.slugify()
|
|
||||||
{{author_slug, year, month, day, post.order}, post}
|
|
||||||
end)
|
|
||||||
|
|
||||||
:ets.insert(@author_table, author_posts)
|
|
||||||
end
|
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -128,29 +107,6 @@ defmodule Mebe2.Engine.DB do
|
||||||
:ets.insert(@tag_table, tag_posts)
|
:ets.insert(@tag_table, tag_posts)
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec insert_author_posts(%{optional(String.t()) => Models.Post.t()}) :: true
|
|
||||||
def insert_author_posts(authors) do
|
|
||||||
author_posts =
|
|
||||||
Enum.reduce(Map.keys(authors), [], fn author_slug, acc ->
|
|
||||||
Enum.reduce(authors[author_slug], acc, fn post, inner_acc ->
|
|
||||||
{{year, month, day}, _} = DateTime.to_erl(post.datetime)
|
|
||||||
[{{author_slug, year, month, day, post.order}, post} | inner_acc]
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
:ets.insert(@author_table, author_posts)
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec insert_author_names(%{optional(String.t()) => String.t()}) :: true
|
|
||||||
def insert_author_names(author_names_map) do
|
|
||||||
author_names =
|
|
||||||
Enum.reduce(Map.keys(author_names_map), [], fn author_slug, acc ->
|
|
||||||
[{{:author_name, author_slug}, author_names_map[author_slug]} | acc]
|
|
||||||
end)
|
|
||||||
|
|
||||||
:ets.insert(@meta_table, author_names)
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec get_menu() :: [Models.MenuItem.t()]
|
@spec get_menu() :: [Models.MenuItem.t()]
|
||||||
def get_menu() do
|
def get_menu() do
|
||||||
case :ets.match(@menu_table, :"$1") do
|
case :ets.match(@menu_table, :"$1") do
|
||||||
|
@ -179,21 +135,6 @@ defmodule Mebe2.Engine.DB do
|
||||||
get_post_list(@tag_table, ms, first, limit)
|
get_post_list(@tag_table, ms, first, limit)
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec get_author_posts(String.t(), integer(), integer()) :: [Models.Post.t()]
|
|
||||||
def get_author_posts(author_slug, first, limit) do
|
|
||||||
ms =
|
|
||||||
fun do
|
|
||||||
{{^author_slug, _, _, _, _}, post} -> post
|
|
||||||
end
|
|
||||||
|
|
||||||
get_post_list(
|
|
||||||
@author_table,
|
|
||||||
ms,
|
|
||||||
first,
|
|
||||||
limit
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec get_year_posts(integer(), integer(), integer()) :: [Models.Post.t()]
|
@spec get_year_posts(integer(), integer(), integer()) :: [Models.Post.t()]
|
||||||
def get_year_posts(year, first, limit) do
|
def get_year_posts(year, first, limit) do
|
||||||
ms =
|
ms =
|
||||||
|
@ -270,11 +211,6 @@ defmodule Mebe2.Engine.DB do
|
||||||
get_meta(type, key, 0)
|
get_meta(type, key, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec get_author_name(String.t()) :: String.t()
|
|
||||||
def get_author_name(author_slug) do
|
|
||||||
get_meta(:author_name, author_slug, author_slug)
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec insert_meta(atom, :all | integer | String.t(), integer | String.t()) :: true
|
@spec insert_meta(atom, :all | integer | String.t(), integer | String.t()) :: true
|
||||||
defp insert_meta(type, key, value) do
|
defp insert_meta(type, key, value) do
|
||||||
:ets.insert(@meta_table, {{type, key}, value})
|
:ets.insert(@meta_table, {{type, key}, value})
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
defmodule Mebe2.Engine.SlugUtils do
|
|
||||||
@moduledoc """
|
|
||||||
Utilities related to handling of slugs.
|
|
||||||
"""
|
|
||||||
|
|
||||||
alias Mebe2.Engine.DB
|
|
||||||
|
|
||||||
@doc """
|
|
||||||
Get slug out of a given value.
|
|
||||||
|
|
||||||
Nil is returned as is.
|
|
||||||
"""
|
|
||||||
@spec slugify(String.t() | nil) :: String.t() | nil
|
|
||||||
def slugify(nil), do: nil
|
|
||||||
|
|
||||||
def slugify(value) do
|
|
||||||
Slugger.slugify_downcase(value)
|
|
||||||
end
|
|
||||||
|
|
||||||
@doc """
|
|
||||||
Get the author name related to this slug from the DB.
|
|
||||||
"""
|
|
||||||
@spec unslugify_author(String.t()) :: String.t()
|
|
||||||
def unslugify_author(slug) do
|
|
||||||
DB.get_author_name(slug)
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,44 +0,0 @@
|
||||||
defmodule Mebe2.Engine.Utils do
|
|
||||||
@moduledoc """
|
|
||||||
This module contains functions and other stuff that just don't fit anywhere else properly.
|
|
||||||
"""
|
|
||||||
|
|
||||||
alias Mebe2.Engine.Models
|
|
||||||
|
|
||||||
@doc """
|
|
||||||
Get the author of a post.
|
|
||||||
|
|
||||||
Returns a value according to the following pseudocode
|
|
||||||
|
|
||||||
if multi author mode is on then
|
|
||||||
if post has author then
|
|
||||||
return post's author
|
|
||||||
else if use default author is on then
|
|
||||||
return blog author
|
|
||||||
else return nil
|
|
||||||
else if use default author is on then
|
|
||||||
return blog author
|
|
||||||
else return nil
|
|
||||||
"""
|
|
||||||
@spec get_author(Models.Post.t()) :: String.t() | nil
|
|
||||||
def get_author(%Models.Post{extra_headers: extra_headers}) do
|
|
||||||
multi_author_mode = Mebe2.get_conf(:multi_author_mode)
|
|
||||||
use_default_author = Mebe2.get_conf(:use_default_author)
|
|
||||||
blog_author = Mebe2.get_conf(:blog_author)
|
|
||||||
|
|
||||||
if multi_author_mode do
|
|
||||||
cond do
|
|
||||||
Map.has_key?(extra_headers, "author") ->
|
|
||||||
Map.get(extra_headers, "author")
|
|
||||||
|
|
||||||
use_default_author ->
|
|
||||||
blog_author
|
|
||||||
|
|
||||||
true ->
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if use_default_author, do: blog_author, else: nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -45,8 +45,6 @@ defmodule Mebe2.Engine.Worker do
|
||||||
pages: pages,
|
pages: pages,
|
||||||
posts: posts,
|
posts: posts,
|
||||||
tags: tags,
|
tags: tags,
|
||||||
authors: authors,
|
|
||||||
author_names: author_names,
|
|
||||||
years: years,
|
years: years,
|
||||||
months: months
|
months: months
|
||||||
} = Crawler.crawl(data_path)
|
} = Crawler.crawl(data_path)
|
||||||
|
@ -64,15 +62,6 @@ defmodule Mebe2.Engine.Worker do
|
||||||
DB.insert_tag_posts(tags)
|
DB.insert_tag_posts(tags)
|
||||||
Enum.each(Map.keys(tags), fn tag -> DB.insert_count(:tag, tag, Enum.count(tags[tag])) end)
|
Enum.each(Map.keys(tags), fn tag -> DB.insert_count(:tag, tag, Enum.count(tags[tag])) end)
|
||||||
|
|
||||||
if Mebe2.get_conf(:multi_author_mode) do
|
|
||||||
DB.insert_author_posts(authors)
|
|
||||||
DB.insert_author_names(author_names)
|
|
||||||
|
|
||||||
Enum.each(Map.keys(authors), fn author ->
|
|
||||||
DB.insert_count(:author, author, Enum.count(authors[author]))
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
# For years and months, only insert the counts (the data can be fetched from main posts table)
|
# For years and months, only insert the counts (the data can be fetched from main posts table)
|
||||||
Enum.each(Map.keys(years), fn year ->
|
Enum.each(Map.keys(years), fn year ->
|
||||||
DB.insert_count(:year, year, Enum.count(years[year]))
|
DB.insert_count(:year, year, Enum.count(years[year]))
|
||||||
|
|
|
@ -4,8 +4,6 @@ defmodule Mebe2 do
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@conf_datatypes %{
|
@conf_datatypes %{
|
||||||
multi_author_mode: :bool,
|
|
||||||
use_default_author: :bool,
|
|
||||||
force_read_more: :bool,
|
force_read_more: :bool,
|
||||||
enable_feeds: :bool,
|
enable_feeds: :bool,
|
||||||
feeds_full_content: :bool,
|
feeds_full_content: :bool,
|
||||||
|
|
|
@ -4,9 +4,7 @@
|
||||||
<![CDATA[<%= raw(post.title) %>]]>
|
<![CDATA[<%= raw(post.title) %>]]>
|
||||||
</title>
|
</title>
|
||||||
|
|
||||||
<%= raw(if Mebe2.get_conf(:multi_author_mode) do %>
|
<dc:creator><%= Mebe2.get_conf(:blog_author) %></dc:creator>
|
||||||
<dc:creator><%= Mebe2.Engine.Utils.get_author(post) %></dc:creator>
|
|
||||||
<% end) %>
|
|
||||||
|
|
||||||
<link><%= Mebe2.get_conf(:absolute_url) %><%= Mebe2.Web.Views.Utils.get_post_path(post) %></link>
|
<link><%= Mebe2.get_conf(:absolute_url) %><%= Mebe2.Web.Views.Utils.get_post_path(post) %></link>
|
||||||
<guid><%= Mebe2.get_conf(:absolute_url) %><%= Mebe2.Web.Views.Utils.get_post_path(post) %></guid>
|
<guid><%= Mebe2.get_conf(:absolute_url) %><%= Mebe2.Web.Views.Utils.get_post_path(post) %></guid>
|
||||||
|
|
1
mix.exs
1
mix.exs
|
@ -26,7 +26,6 @@ defmodule Mebe2.MixProject do
|
||||||
{:raxx, "~> 0.16.1"},
|
{:raxx, "~> 0.16.1"},
|
||||||
{:ace, "~> 0.17.1"},
|
{:ace, "~> 0.17.1"},
|
||||||
{:calendar, "~> 0.17.4"},
|
{:calendar, "~> 0.17.4"},
|
||||||
{:slugger, "~> 0.3.0"},
|
|
||||||
{:ex2ms, "~> 1.5.0"},
|
{:ex2ms, "~> 1.5.0"},
|
||||||
{:mbu, "~> 3.0.0", runtime: false},
|
{:mbu, "~> 3.0.0", runtime: false},
|
||||||
{:exsync, "~> 0.2.3", only: :dev}
|
{:exsync, "~> 0.2.3", only: :dev}
|
||||||
|
|
1
mix.lock
1
mix.lock
|
@ -23,7 +23,6 @@
|
||||||
"ranch": {:hex, :ranch, "1.5.0", "f04166f456790fee2ac1aa05a02745cc75783c2bfb26d39faf6aefc9a3d3a58a", [:rebar3], [], "hexpm"},
|
"ranch": {:hex, :ranch, "1.5.0", "f04166f456790fee2ac1aa05a02745cc75783c2bfb26d39faf6aefc9a3d3a58a", [:rebar3], [], "hexpm"},
|
||||||
"raxx": {:hex, :raxx, "0.16.1", "3737b61f198755138bb2c8c61ed22dc06f9c0cf3218320189ddcda02da91d94a", [:mix], [{:cookie, "~> 0.1.0", [hex: :cookie, repo: "hexpm", optional: false]}, {:eex_html, "~> 0.1.1", [hex: :eex_html, repo: "hexpm", optional: false]}], "hexpm"},
|
"raxx": {:hex, :raxx, "0.16.1", "3737b61f198755138bb2c8c61ed22dc06f9c0cf3218320189ddcda02da91d94a", [:mix], [{:cookie, "~> 0.1.0", [hex: :cookie, repo: "hexpm", optional: false]}, {:eex_html, "~> 0.1.1", [hex: :eex_html, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"raxx_static": {:hex, :raxx_static, "0.6.1", "8b48254fc3d1b8b1e473b7c307fbba0ae767c60482754ce823c664544c85d729", [:mix], [{:mime, "~> 1.1", [hex: :mime, repo: "hexpm", optional: false]}, {:raxx, "~> 0.15.2", [hex: :raxx, repo: "hexpm", optional: false]}], "hexpm"},
|
"raxx_static": {:hex, :raxx_static, "0.6.1", "8b48254fc3d1b8b1e473b7c307fbba0ae767c60482754ce823c664544c85d729", [:mix], [{:mime, "~> 1.1", [hex: :mime, repo: "hexpm", optional: false]}, {:raxx, "~> 0.15.2", [hex: :raxx, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"slugger": {:hex, :slugger, "0.3.0", "efc667ab99eee19a48913ccf3d038b1fb9f165fa4fbf093be898b8099e61b6ed", [:mix], [], "hexpm"},
|
|
||||||
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], [], "hexpm"},
|
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], [], "hexpm"},
|
||||||
"tzdata": {:hex, :tzdata, "0.5.19", "7962a3997bf06303b7d1772988ede22260f3dae1bf897408ebdac2b4435f4e6a", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
|
"tzdata": {:hex, :tzdata, "0.5.19", "7962a3997bf06303b7d1772988ede22260f3dae1bf897408ebdac2b4435f4e6a", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [:rebar3], [], "hexpm"},
|
"unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [:rebar3], [], "hexpm"},
|
||||||
|
|
Reference in a new issue