--- /dev/null
+# page
+
+A static website generator for exactly 1 use case.
+
+"I have a bunch of gemini files that I want to serve as-is, but I also
+want to generate some HTML"
+
+## How to use
+
+1. Stand on the directory you want to turn into a page
+2. run page
+3. your output is in ../<directory_name>_html
+
+So for example:
+
+```
+$ pwd
+/home/rbdr/web/website
+$ page
+$ ls ..
+website/
+website_html/
+```
+
+## Front Matter
+
+You can add some optional front matter. We'll look at the two first lines that
+start with `---`
+
+The format is:
+
+```
+--- title: the title of the page
+--- description: a description
+```
+
+This only works if they are the first lines of the page.
+
+## Local Path Translation
+
+Links that end with `.gmi` will be replaced with `.html` unless they specifically start with `gemini:`
+
+## Layouts
+
+page expects a file called _layout.html in the root. It expects three placeholders:
+
+* {{ content }} the generated HTML from parsing the gemini text files.
+* {{ title }} the frontmatter title or an empty string.
+* {{ description }} the frontmatter description or an empty string.
+
+
+## Hidden folders
+
+Hidden folders get ignored, except for the .well-known folder.
+
+## What happens to files that aren't gemini?
+
+They're copied as-is.
--- /dev/null
+use crate::file_handler::{File, FileHandler};
+use std::fs::read_dir;
+use std::path::PathBuf;
+
+pub fn find_files(directory_path: PathBuf) -> Vec<File> {
+ let mut result: Vec<File> = vec![];
+ let file_handler = FileHandler::default();
+ let entries = read_dir(directory_path).unwrap();
+ for entry in entries {
+ let path = entry.unwrap().path();
+ if path.starts_with(".") && !path.starts_with(".well-known") {
+ continue;
+ }
+ if path.is_dir() {
+ result.append(&mut find_files(path))
+ } else {
+ let file_type = file_handler.identify(&path);
+ result.push(File {
+ path: path,
+ file_type: file_type,
+ });
+ }
+ }
+ return result;
+}
--- /dev/null
+pub struct Strategy {}
+
+use std::path::PathBuf;
+
+use crate::file_handler::{FileType, FileHandlerStrategy};
+
+impl FileHandlerStrategy for Strategy {
+ fn is(&self, path: &PathBuf) -> bool {
+ !path.is_dir()
+ }
+
+ fn identify(&self) -> FileType {
+ FileType::File
+ }
+
+ fn can_handle(&self, path: &PathBuf) -> bool {
+ !path.is_dir()
+ }
+
+ fn handle(&self, path: &PathBuf) {
+ println!("Should copy {}", path.display())
+ }
+}
--- /dev/null
+pub mod file;
--- /dev/null
+mod file_strategies;
+
+use file_strategies::file::Strategy as FileStrategy;
+use std::path::PathBuf;
+
+pub struct FileHandler {
+ pub strategies: Vec<Box<dyn FileHandlerStrategy>>
+}
+
+impl Default for FileHandler {
+ fn default() -> FileHandler {
+ FileHandler {
+ strategies: vec![Box::new(FileStrategy{})]
+ }
+ }
+}
+
+impl FileHandler {
+ pub fn identify(&self, path: &PathBuf) -> FileType {
+ for strategy in self.strategies.iter() {
+ if strategy.is(&path) {
+ return strategy.identify();
+ }
+ }
+ FileType::Unknown
+ }
+
+ pub fn handle(&self, path: &PathBuf) {
+ for strategy in self.strategies.iter() {
+ if strategy.can_handle(path) {
+ return strategy.handle(path);
+ }
+ }
+ }
+}
+
+pub trait FileHandlerStrategy {
+ fn is(&self, path: &PathBuf) -> bool;
+ fn identify(&self) -> FileType;
+ fn can_handle(&self, path: &PathBuf) -> bool;
+ fn handle(&self, path: &PathBuf);
+}
+
+pub enum FileType {
+ Gemini,
+ File,
+ Layout,
+ Unknown,
+}
+
+pub struct File {
+ pub path: PathBuf,
+ pub file_type: FileType,
+}
mod gemini_parser;
+mod file_finder;
+mod file_handler;
+
+use std::env::current_dir;
use crate::gemini_parser::parse;
+use crate::file_finder::find_files;
fn main() {
let gemini_source = "# Test\n## 2nd H\na line\n another line\n```\npreformat\n=> preformat\n```\n=> http://lol.com\n=> http://lol.com lol\n* lol\nbla\n* lol\n* lmao\n> blabla\n> blabla";
let html = parse(gemini_source);
- println!("{}", html)
+ println!("{}", html);
+
+ let files = find_files(current_dir().unwrap());
+ println!("Found {} files", files.len());
}