feat: add url and analysis setting fields.
This commit is contained in:
parent
98f67c6129
commit
62162ea503
@ -0,0 +1 @@
|
|||||||
|
-- This file should undo anything in `up.sql`
|
@ -0,0 +1,4 @@
|
|||||||
|
-- Your SQL goes here
|
||||||
|
|
||||||
|
INSERT INTO setting ("name", "value")
|
||||||
|
VALUES ('url', ''), ('analysis', '');
|
@ -13,6 +13,8 @@ use std::collections::HashMap;
|
|||||||
pub struct SettingMap {
|
pub struct SettingMap {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
|
pub url: String,
|
||||||
|
pub analysis: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <'a, 'r> FromRequest<'a, 'r> for SettingMap {
|
impl <'a, 'r> FromRequest<'a, 'r> for SettingMap {
|
||||||
@ -37,6 +39,9 @@ impl <'a, 'r> FromRequest<'a, 'r> for SettingMap {
|
|||||||
Outcome::Success(SettingMap{
|
Outcome::Success(SettingMap{
|
||||||
title: settings_map.get("title").unwrap_or(&"".to_string()).clone(),
|
title: settings_map.get("title").unwrap_or(&"".to_string()).clone(),
|
||||||
description: settings_map.get("description").unwrap_or(&"".to_string()).clone(),
|
description: settings_map.get("description").unwrap_or(&"".to_string()).clone(),
|
||||||
|
|
||||||
|
url: settings_map.get("url").unwrap_or(&"".to_string()).clone(),
|
||||||
|
analysis: settings_map.get("analysis").unwrap_or(&"".to_string()).clone()
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ pub fn index(setting: SettingMap, conn: DbConn) -> Template {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/archives/<archives_id>")]
|
#[get("/archives/<archives_id>")]
|
||||||
pub fn single_article(conn: DbConn, archives_id: i32) -> Result<Template, Status> {
|
pub fn single_article(setting: SettingMap, conn: DbConn, archives_id: i32) -> Result<Template, Status> {
|
||||||
let mut context = Context::new();
|
let mut context = Context::new();
|
||||||
|
|
||||||
let result: Result<_, _> = articles::table.find(archives_id).first::<Article>(&*conn);
|
let result: Result<_, _> = articles::table.find(archives_id).first::<Article>(&*conn);
|
||||||
@ -41,6 +41,7 @@ pub fn single_article(conn: DbConn, archives_id: i32) -> Result<Template, Status
|
|||||||
|
|
||||||
let article_response = ArticleResponse::from(&article);
|
let article_response = ArticleResponse::from(&article);
|
||||||
|
|
||||||
|
context.insert("setting", &setting);
|
||||||
context.insert("article", &article_response);
|
context.insert("article", &article_response);
|
||||||
|
|
||||||
Ok(Template::render("archives", &context))
|
Ok(Template::render("archives", &context))
|
||||||
|
@ -16,11 +16,11 @@ pub fn rss(setting: SettingMap, conn: DbConn) -> content::Xml<String> {
|
|||||||
let items: Vec<Item> = article_responses.into_iter().map(|item| {
|
let items: Vec<Item> = article_responses.into_iter().map(|item| {
|
||||||
let url = match item.article.url.clone() {
|
let url = match item.article.url.clone() {
|
||||||
Some(content) => if !content.eq("") {
|
Some(content) => if !content.eq("") {
|
||||||
format!("https://www.kilerd.me/{}", content)
|
format!("{}/{}", setting.url, content)
|
||||||
} else {
|
} else {
|
||||||
format!("https://www.kilerd.me/archives/{}", item.article.id)
|
format!("{}/archives/{}", setting.url, item.article.id)
|
||||||
},
|
},
|
||||||
None => format!("https://www.kilerd.me/archives/{}", item.article.id)
|
None => format!("{}/archives/{}", setting.url, item.article.id)
|
||||||
};
|
};
|
||||||
ItemBuilder::default()
|
ItemBuilder::default()
|
||||||
.title(item.article.title.clone())
|
.title(item.article.title.clone())
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
<footer>
|
<footer>
|
||||||
<section class="container">
|
<section class="container">
|
||||||
<p> 自豪地使用 <a href="https://github.com/Kilerd/rubble">Project Rubble</a> 运行。 </p>
|
<p> 自豪地使用 <a href="https://github.com/Kilerd/rubble">Project Rubble</a> 运行。 </p>
|
||||||
|
<div style="display:none">{{ setting.analysis }}</div>
|
||||||
</section>
|
</section>
|
||||||
</footer>
|
</footer>
|
||||||
<script src="/statics/prism.js" type="text/javascript"></script>
|
<script src="/statics/prism.js" type="text/javascript"></script>
|
||||||
|
Loading…
Reference in New Issue
Block a user