Skip to content

Commit

Permalink
bbn: Add sitemap-xml command
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Feb 7, 2023
1 parent f988e98 commit 518ff89
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions bbn/crates/bbn/src/command.rs
Expand Up @@ -10,4 +10,5 @@ pub use self::config::config;
pub use self::date_range::date_range;
pub use self::json::run as json;
pub use self::list::list;
pub use self::sitemap_xml::run as sitemap_xml;
pub use self::view::view;
7 changes: 5 additions & 2 deletions bbn/crates/bbn/src/command/sitemap_xml.rs
Expand Up @@ -2,7 +2,7 @@ use std::{fs::File, io::BufWriter, path::PathBuf};

use anyhow::Context;
use bbn_repository::{BbnRepository, Query};
use sitemap_xml::writer::SitemapWriter;
use sitemap_xml::writer::{SitemapWriter, Url};

use crate::config_repository::ConfigRepository;

Expand All @@ -27,7 +27,10 @@ pub fn run(out_dir: PathBuf) -> anyhow::Result<()> {
let yyyy = date.year().to_string();
let mm = date.month().to_string();
let dd = date.day_of_month().to_string();
writer.write(format!("https://blog.bouzuya.net/{yyyy}/{mm}/{dd}/").as_str())?;
// TODO: lastmod
writer.write(Url::loc(
format!("https://blog.bouzuya.net/{yyyy}/{mm}/{dd}/").as_str(),
)?)?;
}

writer.end()?;
Expand Down
17 changes: 10 additions & 7 deletions bbn/crates/bbn/src/main.rs
Expand Up @@ -40,6 +40,11 @@ enum Subcommand {
#[structopt(long = "week-date", help = "Prints the date range as week date")]
week_date: bool,
},
#[structopt(name = "hatena-blog", about = "hatena-blog")]
HatenaBlog {
#[structopt(subcommand)]
subcommand: HatenaBlogSubcommand,
},
#[structopt(name = "json", about = "...")]
Json { out_dir: PathBuf },
#[structopt(name = "list", about = "Lists the blog posts")]
Expand All @@ -49,11 +54,8 @@ enum Subcommand {
#[structopt(name = "query", help = "query")]
query: String,
},
#[structopt(name = "hatena-blog", about = "hatena-blog")]
HatenaBlog {
#[structopt(subcommand)]
subcommand: HatenaBlogSubcommand,
},
#[structopt(name = "sitemap-xml", about = "...")]
SitemapXml { out_dir: PathBuf },
#[structopt(name = "view", about = "Views the blog post")]
View {
#[structopt(long = "content", help = "Prints the contents of the entry")]
Expand Down Expand Up @@ -124,8 +126,6 @@ async fn main() -> anyhow::Result<()> {
hatena_blog_data_file,
} => command::config(data_dir, hatena_blog_data_file),
Subcommand::DateRange { month, week_date } => command::date_range(month, week_date),
Subcommand::Json { out_dir } => command::json(out_dir),
Subcommand::List { json, query } => command::list(json, query),
Subcommand::HatenaBlog { subcommand } => match subcommand {
HatenaBlogSubcommand::Diff { date } => command::hatena_blog::diff(date).await,
HatenaBlogSubcommand::Download {
Expand All @@ -146,6 +146,9 @@ async fn main() -> anyhow::Result<()> {
web,
} => command::hatena_blog::view(content, date, hatena_blog_id, meta, web).await,
},
Subcommand::Json { out_dir } => command::json(out_dir),
Subcommand::List { json, query } => command::list(json, query),
Subcommand::SitemapXml { out_dir } => command::sitemap_xml(out_dir),
Subcommand::View {
content,
date,
Expand Down

0 comments on commit 518ff89

Please sign in to comment.