Write index.html file to output

This gives a simple landing page with a rel=alternate link to the feed.

Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
This commit is contained in:
Jacob Kiers 2022-11-29 23:07:11 +01:00
parent 7658748fa7
commit 0f65550169
2 changed files with 14 additions and 5 deletions

View File

@ -1,8 +1,12 @@
<!DOCTYPE html>
<html>
<head><title>Newsletters</title></head>
<head>
<title>Newsletters</title>
<link rel="alternate" type="application/atom+xml" title="ATOM feed" href="./feed.atom" />
</head>
<body>
<h1>Newsletters 2 Web</h1>
<p>The real feed can be found at <a href="./feed.atom">feed.atom</a></p>
<p>Nothing to see here.</p>
<p>This is a public landing page for an instance of the
<a href="https://code.kiers.eu/newsletter-to-web/newsletter-to-web">Newsletters 2 Web</a>

View File

@ -17,6 +17,8 @@ use std::{
pub(crate) use message::Message;
const INDEX_HTML: & 'static str = include_str!("../resources/index.html");
fn main() -> Result<(), Box<dyn Error>> {
let cli = cli::Cli::parse();
@ -96,6 +98,8 @@ fn build_feed(filename: &PathBuf, hostname: String, include_html: bool) -> Resul
write_file(&path, processed_html.as_bytes())?;
}
write_file(dir.join("index.html"), INDEX_HTML)?;
feed::add_entry_to_feed(&mut feed, &msg, &processed_html, &hostname, include_html);
}
@ -191,11 +195,12 @@ fn process_html(input: &str) -> Result<String, ()> {
Ok(input.replace("src", "data-source"))
}
fn write_file(html_path: &PathBuf, data: &[u8]) -> Result<(), std::io::Error> {
fn write_file<P: Into<PathBuf>, D: AsRef<[u8]>>(html_path: P, data: D) -> Result<(), std::io::Error> {
let path : PathBuf = html_path.into();
OpenOptions::new()
.write(true)
.create(true)
.open(&html_path)
.expect(format!("Could not open file '{}' for writing", &html_path.display()).as_str())
.write_all(data)
.open(&path)
.expect(format!("Could not open file '{}' for writing", &path.display()).as_str())
.write_all(data.as_ref())
}