Skip to content

Commit 0638349

Browse files
committed
Make homepage resource filter customizable.
1 parent a306e87 commit 0638349

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/main.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use resource::{
4040
ListingSectionFilter, NoteSectionFilter, Page, PictureSectionFilter, PostSectionFilter,
4141
Renderable, Resource, ResourceKind, Section,
4242
};
43-
use site::Site;
43+
use site::{HomepageFilter, Site};
4444
use theme::{Theme, ThemeConfig};
4545

4646
const ALL_THEMES_URL: &str =
@@ -445,7 +445,20 @@ async fn handle_request(request: Request<State>) -> tide::Result<Response> {
445445
.get(&format!("/{}", &slug))
446446
.unwrap_or(&default_index);
447447
if resource_path == "/" {
448-
posts_section = Some(Section::from_resource(r, &site)?);
448+
match &site.config.homepage_filter {
449+
Some(HomepageFilter::Posts) | None => {
450+
posts_section = Some(Section::from_resource(r, &site)?);
451+
}
452+
Some(HomepageFilter::Notes) => {
453+
notes_section = Some(Section::from_resource(r, &site)?);
454+
}
455+
Some(HomepageFilter::Pictures) => {
456+
pictures_section = Some(Section::from_resource(r, &site)?);
457+
}
458+
Some(HomepageFilter::Listings) => {
459+
listings_section = Some(Section::from_resource(r, &site)?);
460+
}
461+
}
449462
}
450463
if resource_path == "/posts" {
451464
posts_section = Some(Section::from_resource(r, &site)?);
@@ -1280,10 +1293,12 @@ fn load_or_create_sites(
12801293

12811294
if try_import_ig(root_path, &site, &secret_key)? {
12821295
site.config.theme = site::DEFAULT_THEME_PHOTOBLOG.to_string();
1296+
site.config.homepage_filter = Some(HomepageFilter::Pictures);
12831297
site::save_config(&config_path, &site.config)?;
12841298
site = site::load_site(root_path, &domain, themes, &None)?;
12851299
} else if try_import_twitter(root_path, &site, &secret_key)? {
12861300
site.config.theme = site::DEFAULT_THEME_MICROBLOG.to_string();
1301+
site.config.homepage_filter = Some(HomepageFilter::Notes);
12871302
site::save_config(&config_path, &site.config)?;
12881303
site = site::load_site(root_path, &domain, themes, &None)?;
12891304
}

src/site.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ fn default_feed_filenames() -> Vec<String> {
5858
return vec!["atom.xml".to_string()];
5959
}
6060

61+
#[derive(Clone, Debug, Deserialize, Serialize)]
62+
#[serde(rename_all = "snake_case")]
63+
pub enum HomepageFilter {
64+
Posts,
65+
Notes,
66+
Pictures,
67+
Listings,
68+
}
69+
6170
#[derive(Clone, Debug, Deserialize, Serialize)]
6271
pub struct SiteConfig {
6372
pub base_url: String,
@@ -67,6 +76,7 @@ pub struct SiteConfig {
6776
pub theme: String,
6877
pub title: Option<String>,
6978
pub description: Option<String>,
79+
pub homepage_filter: Option<HomepageFilter>,
7080

7181
// required by some themes
7282
pub author: Option<String>,
@@ -93,6 +103,7 @@ impl SiteConfig {
93103
theme: theme.to_string(),
94104
title: None,
95105
description: None,
106+
homepage_filter: None,
96107
author: None,
97108
feed_filename: default_feed_filename(),
98109
feed_filenames: default_feed_filenames(),

0 commit comments

Comments
 (0)