Propagate theme in ArticleRevisions from the state struct

This commit is contained in:
Magnus Hovland Hoff 2018-09-21 08:57:35 +02:00
parent b777a92a48
commit c82228f019
4 changed files with 42 additions and 2 deletions

View file

@ -13,7 +13,7 @@ embed_migrations!();
struct SqliteInitializer; struct SqliteInitializer;
#[allow(dead_code)] #[allow(dead_code)]
mod sqlfunc { pub mod sqlfunc {
use diesel::sql_types::Text; use diesel::sql_types::Text;
sql_function!(fn markdown_to_fts(text: Text) -> Text); sql_function!(fn markdown_to_fts(text: Text) -> Text);
sql_function!(fn theme_from_str_hash(text: Text) -> Text); sql_function!(fn theme_from_str_hash(text: Text) -> Text);

View file

@ -1,5 +1,7 @@
use chrono; use chrono;
use theme::Theme;
fn slug_link(slug: &str) -> &str { fn slug_link(slug: &str) -> &str {
if slug.is_empty() { if slug.is_empty() {
"." "."
@ -23,6 +25,8 @@ pub struct ArticleRevision {
pub latest: bool, pub latest: bool,
pub author: Option<String>, pub author: Option<String>,
pub theme: Theme,
} }
impl ArticleRevision { impl ArticleRevision {

View file

@ -103,7 +103,7 @@ impl Resource for ArticleResource {
.with_body(Layout { .with_body(Layout {
base: None, // Hmm, should perhaps accept `base` as argument base: None, // Hmm, should perhaps accept `base` as argument
title: &data.title, title: &data.title,
theme: theme::theme_from_str_hash(&data.title), theme: data.theme,
body: &Template { body: &Template {
revision: data.revision, revision: data.revision,
last_updated: Some(&last_updated( last_updated: Some(&last_updated(

View file

@ -126,6 +126,18 @@ impl<'a> SyncState<'a> {
Ok(article_revisions::table Ok(article_revisions::table
.filter(article_revisions::article_id.eq(article_id)) .filter(article_revisions::article_id.eq(article_id))
.filter(article_revisions::revision.eq(revision)) .filter(article_revisions::revision.eq(revision))
.select((
article_revisions::sequence_number,
article_revisions::article_id,
article_revisions::revision,
article_revisions::created,
article_revisions::slug,
article_revisions::title,
article_revisions::body,
article_revisions::latest,
article_revisions::author,
::db::sqlfunc::theme_from_str_hash(article_revisions::title),
))
.first::<models::ArticleRevision>(self.db_connection) .first::<models::ArticleRevision>(self.db_connection)
.optional()?) .optional()?)
} }
@ -310,6 +322,18 @@ impl<'a> SyncState<'a> {
Ok(UpdateResult::Success(article_revisions::table Ok(UpdateResult::Success(article_revisions::table
.filter(article_revisions::article_id.eq(article_id)) .filter(article_revisions::article_id.eq(article_id))
.filter(article_revisions::revision.eq(new_revision)) .filter(article_revisions::revision.eq(new_revision))
.select((
article_revisions::sequence_number,
article_revisions::article_id,
article_revisions::revision,
article_revisions::created,
article_revisions::slug,
article_revisions::title,
article_revisions::body,
article_revisions::latest,
article_revisions::author,
::db::sqlfunc::theme_from_str_hash(article_revisions::title),
))
.first::<models::ArticleRevision>(self.db_connection)? .first::<models::ArticleRevision>(self.db_connection)?
)) ))
}) })
@ -358,6 +382,18 @@ impl<'a> SyncState<'a> {
Ok(article_revisions::table Ok(article_revisions::table
.filter(article_revisions::article_id.eq(article_id)) .filter(article_revisions::article_id.eq(article_id))
.filter(article_revisions::revision.eq(new_revision)) .filter(article_revisions::revision.eq(new_revision))
.select((
article_revisions::sequence_number,
article_revisions::article_id,
article_revisions::revision,
article_revisions::created,
article_revisions::slug,
article_revisions::title,
article_revisions::body,
article_revisions::latest,
article_revisions::author,
::db::sqlfunc::theme_from_str_hash(article_revisions::title),
))
.first::<models::ArticleRevision>(self.db_connection)? .first::<models::ArticleRevision>(self.db_connection)?
) )
}) })