Skip to content

Commit

Permalink
feat(ssg): ✨ migrated to http-handle crate
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienrousseau committed Oct 13, 2024
1 parent 6e6cf7d commit afe7754
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 855 deletions.
40 changes: 19 additions & 21 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["ssg", "ssg-cli", "ssg-core", "ssg-i18n", "ssg-server", "ssg-template"]
members = ["ssg", "ssg-cli", "ssg-core", "ssg-i18n", "ssg-template"]
resolver = "2"

[workspace.package]
Expand Down
4 changes: 2 additions & 2 deletions ssg-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ comrak = "0.29"
dtt = "0.0.8"
env_logger = "0.11"
html-generator = "0.0.1"
http-handle = "0.0.2"
lazy_static = "1.5"
log = { version = "0.4", features = ["std"] }
metadata-gen = "0.0.1"
Expand All @@ -22,7 +23,7 @@ quick-xml = "0.36"
regex = "1.10"
reqwest = { version = "0.12", features = ["blocking", "json"] }
rlg = "0.0.6"
rss-gen = "0.0.1"
rss-gen = "0.0.2"
serde = { version = "1.0.210", features = ["derive"] }
serde_json = "1.0"
sitemap-gen = "0.0.1"
Expand All @@ -32,7 +33,6 @@ yaml-rust2 = "0.9"
uuid = { version = "1.10", features = ["v4"] }
vrd = "0.0.8"

ssg-server = { path = "../ssg-server", version = "0.0.1" }
ssg-template = { path = "../ssg-template", version = "0.0.1" }

[build-dependencies]
Expand Down
136 changes: 105 additions & 31 deletions ssg-core/src/compiler/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
use anyhow::{Context as AnyhowContext, Result};
use html_generator::{generate_html, HtmlConfig};
use rlg::log_level::LogLevel;
use rss_gen::{data::RssData, generate_rss, macro_set_rss_data_fields};
use rss_gen::{
data::{RssData, RssDataField, RssItem, RssItemField},
generate_rss, macro_set_rss_data_fields,
};
use sitemap_gen::create_site_map_data;
use std::time::Duration;

Expand Down Expand Up @@ -32,10 +35,6 @@ use std::{collections::HashMap, fs, path::Path};
/// writes the resulting pages to an output directory. Also generates an index
/// page containing links to the generated pages.
///
/// This function takes paths to source, output, site, and template directories
/// as arguments and performs the compilation process. It reads Markdown files,
/// extracts metadata, generates HTML content, and writes resulting pages.
///
/// # Arguments
///
/// * `build_dir_path` - The path to the temporary build directory.
Expand Down Expand Up @@ -178,41 +177,116 @@ fn process_file(
metadata.get("layout").cloned().unwrap_or_default().as_str(),
)?;

Check warning on line 178 in ssg-core/src/compiler/service.rs

View check run for this annotation

Codecov / codecov/patch

ssg-core/src/compiler/service.rs#L177-L178

Added lines #L177 - L178 were not covered by tests

// Generate RSS data
// Generate RSS data for the main feed
let mut rss_data = RssData::new(None);

Check warning on line 181 in ssg-core/src/compiler/service.rs

View check run for this annotation

Codecov / codecov/patch

ssg-core/src/compiler/service.rs#L181

Added line #L181 was not covered by tests

// Set fields using the helper macro
// Set fields using the helper macro for feed-level metadata
macro_set_rss_data_fields!(
rss_data,

Check warning on line 185 in ssg-core/src/compiler/service.rs

View check run for this annotation

Codecov / codecov/patch

ssg-core/src/compiler/service.rs#L184-L185

Added lines #L184 - L185 were not covered by tests
atom_link = macro_metadata_option!(metadata, "atom_link"),
author = macro_metadata_option!(metadata, "author"),
category = macro_metadata_option!(metadata, "category"),
copyright = macro_metadata_option!(metadata, "copyright"),
description = macro_metadata_option!(metadata, "description"),
docs = macro_metadata_option!(metadata, "docs"),
generator = macro_metadata_option!(metadata, "generator"),
image = macro_metadata_option!(metadata, "image"),
item_guid = macro_metadata_option!(metadata, "item_guid"),
item_description =
macro_metadata_option!(metadata, "item_description"),
item_link = macro_metadata_option!(metadata, "item_link"),
item_pub_date =
macro_metadata_option!(metadata, "item_pub_date"),
item_title = macro_metadata_option!(metadata, "item_title"),
language = macro_metadata_option!(metadata, "language"),
last_build_date =
AtomLink = macro_metadata_option!(metadata, "atom_link"),
Author = macro_metadata_option!(metadata, "author"),
Category = macro_metadata_option!(metadata, "category"),
Copyright = macro_metadata_option!(metadata, "copyright"),
Description = macro_metadata_option!(metadata, "description"),
Docs = macro_metadata_option!(metadata, "docs"),
Generator = macro_metadata_option!(metadata, "generator"),
ImageUrl = macro_metadata_option!(metadata, "image"),
Guid = macro_metadata_option!(metadata, "guid"),
Language = macro_metadata_option!(metadata, "language"),
LastBuildDate =
macro_metadata_option!(metadata, "last_build_date"),
link = macro_metadata_option!(metadata, "permalink"),
managing_editor =
Link = macro_metadata_option!(metadata, "permalink"),
ManagingEditor =
macro_metadata_option!(metadata, "managing_editor"),
pub_date = macro_metadata_option!(metadata, "pub_date"),
title = macro_metadata_option!(metadata, "title"),
ttl = macro_metadata_option!(metadata, "ttl"),
webmaster = macro_metadata_option!(metadata, "webmaster")
PubDate = macro_metadata_option!(metadata, "pub_date"),
Title = macro_metadata_option!(metadata, "title"),
Ttl = macro_metadata_option!(metadata, "ttl"),
Webmaster = macro_metadata_option!(metadata, "webmaster")
);

// Handle RSS item data
if metadata.contains_key("item_title")
&& metadata.contains_key("item_description")

Check warning on line 209 in ssg-core/src/compiler/service.rs

View check run for this annotation

Codecov / codecov/patch

ssg-core/src/compiler/service.rs#L208-L209

Added lines #L208 - L209 were not covered by tests
{
let mut rss_item = RssItem::new();

Check warning on line 211 in ssg-core/src/compiler/service.rs

View check run for this annotation

Codecov / codecov/patch

ssg-core/src/compiler/service.rs#L211

Added line #L211 was not covered by tests

rss_item = rss_item.set(
RssItemField::Title,

Check warning on line 214 in ssg-core/src/compiler/service.rs

View check run for this annotation

Codecov / codecov/patch

ssg-core/src/compiler/service.rs#L213-L214

Added lines #L213 - L214 were not covered by tests
macro_metadata_option!(metadata, "item_title"),
);
rss_item = rss_item.set(
RssItemField::Link,

Check warning on line 218 in ssg-core/src/compiler/service.rs

View check run for this annotation

Codecov / codecov/patch

ssg-core/src/compiler/service.rs#L217-L218

Added lines #L217 - L218 were not covered by tests
macro_metadata_option!(metadata, "item_link"),
);
rss_item = rss_item.set(
RssItemField::Description,

Check warning on line 222 in ssg-core/src/compiler/service.rs

View check run for this annotation

Codecov / codecov/patch

ssg-core/src/compiler/service.rs#L221-L222

Added lines #L221 - L222 were not covered by tests
macro_metadata_option!(metadata, "item_description"),
);

if metadata.contains_key("item_guid") {
rss_item = rss_item.set(
RssItemField::Guid,

Check warning on line 228 in ssg-core/src/compiler/service.rs

View check run for this annotation

Codecov / codecov/patch

ssg-core/src/compiler/service.rs#L226-L228

Added lines #L226 - L228 were not covered by tests
macro_metadata_option!(metadata, "item_guid"),
);
}

if metadata.contains_key("item_pub_date") {
rss_item = rss_item.set(
RssItemField::PubDate,

Check warning on line 235 in ssg-core/src/compiler/service.rs

View check run for this annotation

Codecov / codecov/patch

ssg-core/src/compiler/service.rs#L233-L235

Added lines #L233 - L235 were not covered by tests
macro_metadata_option!(metadata, "item_pub_date"),
);
}

// Only add the RSS item if it contains valid title, link, and description
if !rss_item.title.is_empty()
&& !rss_item.link.is_empty()
&& !rss_item.description.is_empty()

Check warning on line 243 in ssg-core/src/compiler/service.rs

View check run for this annotation

Codecov / codecov/patch

ssg-core/src/compiler/service.rs#L241-L243

Added lines #L241 - L243 were not covered by tests
{
rss_data.add_item(rss_item);

Check warning on line 245 in ssg-core/src/compiler/service.rs

View check run for this annotation

Codecov / codecov/patch

ssg-core/src/compiler/service.rs#L245

Added line #L245 was not covered by tests
}
}

Check warning on line 247 in ssg-core/src/compiler/service.rs

View check run for this annotation

Codecov / codecov/patch

ssg-core/src/compiler/service.rs#L247

Added line #L247 was not covered by tests

// Ensure managingEditor and webMaster have real names in the format "email (Real Name)"
let managing_editor =
macro_metadata_option!(metadata, "managing_editor");
if !managing_editor.contains('(') {
rss_data = rss_data.set(
RssDataField::ManagingEditor,
format!("{} (Default Name)", managing_editor),

Check warning on line 255 in ssg-core/src/compiler/service.rs

View check run for this annotation

Codecov / codecov/patch

ssg-core/src/compiler/service.rs#L252-L255

Added lines #L252 - L255 were not covered by tests
);
}

let web_master = macro_metadata_option!(metadata, "webmaster");
if !web_master.contains('(') {
rss_data = rss_data.set(
RssDataField::Webmaster,
format!("{} (Default Name)", web_master),

Check warning on line 263 in ssg-core/src/compiler/service.rs

View check run for this annotation

Codecov / codecov/patch

ssg-core/src/compiler/service.rs#L260-L263

Added lines #L260 - L263 were not covered by tests
);
}

// Validate image format - if it’s not JPEG or PNG, use a default image
let image_url = macro_metadata_option!(metadata, "image");
if !(image_url.ends_with(".jpg")
|| image_url.ends_with(".jpeg")
|| image_url.ends_with(".png")
|| image_url.ends_with(".gif")
|| image_url.ends_with(".webp"))

Check warning on line 273 in ssg-core/src/compiler/service.rs

View check run for this annotation

Codecov / codecov/patch

ssg-core/src/compiler/service.rs#L269-L273

Added lines #L269 - L273 were not covered by tests
{
rss_data = rss_data.set(
RssDataField::ImageUrl,
image_url.clone(),

Check warning on line 277 in ssg-core/src/compiler/service.rs

View check run for this annotation

Codecov / codecov/patch

ssg-core/src/compiler/service.rs#L275-L277

Added lines #L275 - L277 were not covered by tests
);
}

// Fix atom:link href value to ensure it matches the actual RSS location
rss_data = rss_data.set(
RssDataField::AtomLink,
format!("{}/rss.xml", image_url),

Check warning on line 284 in ssg-core/src/compiler/service.rs

View check run for this annotation

Codecov / codecov/patch

ssg-core/src/compiler/service.rs#L282-L284

Added lines #L282 - L284 were not covered by tests
);

// Generate RSS
// Generate RSS XML
let rss = generate_rss(&rss_data)?;

Check warning on line 288 in ssg-core/src/compiler/service.rs

View check run for this annotation

Codecov / codecov/patch

ssg-core/src/compiler/service.rs#L288

Added line #L288 was not covered by tests
// println!("{}", &rss);

// Generate various data structures
let json = create_manifest_data(&metadata);
Expand Down
2 changes: 1 addition & 1 deletion ssg-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub mod utilities;

// Re-export commonly used items for easier access
pub use compiler::service::compile;
pub use http_handle::Server;
pub use loggers::init_logger;
pub use ssg_server::Server;
pub use ssg_template;
pub use utilities::uuid::generate_unique_string;
51 changes: 0 additions & 51 deletions ssg-server/Cargo.toml

This file was deleted.

Empty file removed ssg-server/README.md
Empty file.
Loading

0 comments on commit afe7754

Please sign in to comment.