Skip to content

Commit

Permalink
Add JSONFeed
Browse files Browse the repository at this point in the history
  • Loading branch information
hongquan committed Sep 1, 2023
1 parent 16bc08f commit 13fea92
Show file tree
Hide file tree
Showing 14 changed files with 347 additions and 20 deletions.
171 changes: 164 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ default-run = "quanweb"
strip="debuginfo"

[dependencies]
ammonia = "3.3.0"
async-fred-session = "0.1.5"
async-trait = "0.1.71"
atom_syndication = { version = "0.12.2", features = ["serde"] }
Expand Down
1 change: 1 addition & 0 deletions src/front/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ pub fn get_router() -> Router<AppState> {
.route("/talk/", get(views::minors::list_talks))
.route("/book/", get(views::minors::list_books))
.route("/feeds.atom", get(views::feeds::gen_atom_feeds))
.route("/feeds.json", get(views::feeds::gen_json_feeds))
.route("/api/set-lang", post(views::set_lang))
}
10 changes: 10 additions & 0 deletions src/front/structs.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::num::NonZeroU16;

use serde::Deserialize;

Expand All @@ -11,6 +12,15 @@ pub struct LaxPaging {
pub page: Option<String>,
}

impl LaxPaging {
/// Get the page as non-zero number (default to 1).
/// The type is NonZeroU16 because our website is small enough for page number
/// to be fit in u16.
pub fn get_page_as_number(&self) -> NonZeroU16 {
self.page.as_deref().map(|s| s.parse().ok()).flatten().unwrap_or(NonZeroU16::MIN)
}
}

#[derive(Debug, Clone, Deserialize)]
pub struct SetLangReq {
pub lang: String,
Expand Down
5 changes: 1 addition & 4 deletions src/front/views/blog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ pub async fn list_posts(
State(state): State<AppState>,
) -> AxumResult<Html<String>> {
let AppState { db, jinja } = state;
let current_page = paging
.page
.and_then(|p| NonZeroU16::new(p.parse().ok()?))
.unwrap_or(NonZeroU16::MIN);
let current_page = paging.get_page_as_number();
let page_size = DEFAULT_PAGE_SIZE;
let offset = ((current_page.get() - 1) * page_size as u16) as i64;
let cat = stores::blog::get_category_by_slug(&cat_slug, &db)
Expand Down
Loading

0 comments on commit 13fea92

Please sign in to comment.