diff --git a/src/db.rs b/src/db.rs index 12c80a5..5308191 100644 --- a/src/db.rs +++ b/src/db.rs @@ -13,7 +13,7 @@ embed_migrations!(); struct SqliteInitializer; #[allow(dead_code)] -mod sqlfunc { +pub mod sqlfunc { use diesel::sql_types::Text; sql_function!(fn markdown_to_fts(text: Text) -> Text); sql_function!(fn theme_from_str_hash(text: Text) -> Text); diff --git a/src/models.rs b/src/models.rs index e43ecbd..3819670 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1,5 +1,7 @@ use chrono; +use theme::Theme; + fn slug_link(slug: &str) -> &str { if slug.is_empty() { "." @@ -23,6 +25,8 @@ pub struct ArticleRevision { pub latest: bool, pub author: Option, + + pub theme: Theme, } impl ArticleRevision { diff --git a/src/resources/article_resource.rs b/src/resources/article_resource.rs index 6221c8f..947c20e 100644 --- a/src/resources/article_resource.rs +++ b/src/resources/article_resource.rs @@ -103,7 +103,7 @@ impl Resource for ArticleResource { .with_body(Layout { base: None, // Hmm, should perhaps accept `base` as argument title: &data.title, - theme: theme::theme_from_str_hash(&data.title), + theme: data.theme, body: &Template { revision: data.revision, last_updated: Some(&last_updated( diff --git a/src/state.rs b/src/state.rs index f73ea32..85a9833 100644 --- a/src/state.rs +++ b/src/state.rs @@ -126,6 +126,18 @@ impl<'a> SyncState<'a> { Ok(article_revisions::table .filter(article_revisions::article_id.eq(article_id)) .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::(self.db_connection) .optional()?) } @@ -310,6 +322,18 @@ impl<'a> SyncState<'a> { Ok(UpdateResult::Success(article_revisions::table .filter(article_revisions::article_id.eq(article_id)) .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::(self.db_connection)? )) }) @@ -358,6 +382,18 @@ impl<'a> SyncState<'a> { Ok(article_revisions::table .filter(article_revisions::article_id.eq(article_id)) .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::(self.db_connection)? ) })