Skip to content

Commit

Permalink
Fix bug where collections wouldn't update, experimenting with Jekyll-…
Browse files Browse the repository at this point in the history
…like serving

Major performance regression, likely due to new serving. Will likely end up reverting this change. This commit simply exists to save this experimental change (and to show I did a lot of work today!), while also pushing through the bugfix that resulted from it.
  • Loading branch information
Emil Sayahi committed Nov 27, 2020
1 parent 82a1be2 commit 47894eb
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 89 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ version = "0.1.3"
authors = ["Emil Sayahi <limesayahi@gmail.com>"]
edition = "2018"
categories = ["command-line-utilities", "parser-implementations", "text-processing"]
exclude = ["/.github/**/*", "/branding/**/*", "/.gitignore", "/.whitesource", "/azure-pipelines.yml", "/snapcraft.yaml", "/TODO"]
exclude = ["/.github/**/*", "/branding/**/*", "/.gitignore", "/.whitesource", "/azure-pipelines.yml", "/snapcraft.yaml", "/TODO.md"]
license = "AGPL-3.0-or-later"
description = "Mokk (Macro Output Key Kit) implementation written in Rust."
repository = "https://github.com/MadeByEmil/dokkoo"
Expand Down
46 changes: 0 additions & 46 deletions TODO

This file was deleted.

55 changes: 55 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Chores:
* Keep documentation up to date & complete
* Maintain secure codebase
* Conform to Rust styleguide
* Complete all TODOs in codebase

WIP:
- [ ] Re-implement collections
i. When building, create collections: HashMap<collection: String, Vec<page: Page>>
ii. As compiling, append to collection's Vec<page>
iii. Recombine collection Vec<Page> into collections
iv. Write collections to binary file
- [ ] Test current implementation
- [x] ~~Fully implement collections~~
i. As compiling, append to HashMap<collection: String, Vec<page: Page>>
ii. Incorporate into contexts as 'collections' context
iii. Compile files at root last
- [x] Test current implementation
- [x] Look into replacing current Markdown processor
* Very sensitive with whitespace
* Performance could be improved
- [x] Test replacement implementation
- [ ] Look into replacing Liquid crate(s)
* Basic logic blocks, like 'if' statements and 'for' loops are not properly implemented
* Performance could be improved
- [ ] Test replacement implementation

Distribution plans:
* Consider iterating on branding prior to releases
* Linux-based operating systems (primary CLI release target)
- [x] Binary
- [x] Debian package
- [x] RPM package
- [ ] COPR
- [] Gentoo
- [x] Snapcraft
- [ ] Flatpak
- [x] Arch User Repository packages ('dokkoo-bin')
* Rust Crate (primary library release target)
- [x] crates.io
* Unix-like operating systems
- [ ] pkgsrc (planned; technically intended for NetBSD)
- [ ] Nix
* Opensource BSD-based operating systems
- [ ] FreeBSD Ports
- [ ] OpenBSD Ports
* macOS & PureDarwin
- [x] Binary
- [ ] Homebrew (planned; technically available for Linux as well)
- [ ] Fink (planned; technically available for Linux as well)
- [ ] MacPorts
* Windows
- [x] Binary
- [ ] Chocolatey
- [ ] Scoop
29 changes: 19 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ pub struct Page {
/// * `weekdate` → `/{{ page.document.frontmatter.collection }}/{{ page.year }}/W{{ page.week }}/{{ page.short_day }}/{{ page.document.frontmatter.title }}.html`
///
/// * `none` → `/{{ page.document.frontmatter.collection }}/{{ page.document.frontmatter.title }}.html`
#[inline(always)]
pub fn get_permalink(permalink: &str) -> String {
match &*permalink {
"date" => {
Expand Down Expand Up @@ -135,6 +136,7 @@ pub fn get_permalink(permalink: &str) -> String {
/// # Arguments
///
/// * `page_text` - The `.mokkf` file's data as a `String`
#[inline(always)]
pub fn split_frontmatter(page_text: String) -> (String, String) {
let mut begin = false;
let mut end = false;
Expand Down Expand Up @@ -167,6 +169,7 @@ pub fn split_frontmatter(page_text: String) -> (String, String) {
/// * `page_path` - The `.mokkf` file's path as a `String`
///
/// * `conditions` - Prints conditions information
#[inline(always)]
pub fn get_page_object(page_path: String, collections: &HashMap<String, Vec<Page>>) -> Page {
// Define variables which we'll use to create our Document, which we'll use to generate the Page context
let split_page = split_frontmatter(fs::read_to_string(&page_path).unwrap()); // See file::split_frontmatter
Expand Down Expand Up @@ -303,6 +306,7 @@ pub fn get_page_object(page_path: String, collections: &HashMap<String, Vec<Page
/// * `conditions` - Prints conditions information
///
/// * `snippet_context` - An optional context for rendering snippets, giving them a context from their call arguments
#[inline(always)]
pub fn get_contexts(
page: &Page,
collections: &HashMap<String, Vec<Page>>,
Expand Down Expand Up @@ -372,6 +376,7 @@ pub fn get_contexts(
/// * `only_context` - Whether or not to only render the contexts of a File
///
/// * `collections` - Collection store of this build
#[inline(always)]
pub fn render(
page: &Page,
text_to_render: &str,
Expand Down Expand Up @@ -437,6 +442,7 @@ pub fn render(
/// * `page` - The `.mokkf` file's context as a Page
///
/// * `collections` - Collection store of this build
#[inline(always)]
pub fn compile(
mut page: Page,
mut collections: HashMap<String, Vec<Page>>,
Expand Down Expand Up @@ -474,19 +480,15 @@ pub fn compile(
match collection_name {
None => {}
Some(_) => {
match collections.contains_key(&collection_name.unwrap().as_str().unwrap().to_string())
let collection_name_str = collection_name.unwrap().as_str().unwrap();
match collections.contains_key(&collection_name_str.to_string())
{
true => {
let mut current_collection_entries = collections
.get_key_value(collection_name.unwrap().as_str().unwrap())
.unwrap()
.1
.to_vec();
current_collection_entries.push(page);
true => {
(*collections.get_mut(collection_name_str).unwrap()).push(page);
}
false => {
collections.insert(
collection_name.unwrap().as_str().unwrap().to_string(),
collection_name_str.to_owned(),
vec![page],
);
}
Expand All @@ -506,6 +508,7 @@ pub fn compile(
/// * `layout` - The File's layout's context as a Page
///
/// * `collections` - Collection store of this build
#[inline(always)]
pub fn render_layouts(
sub: &Page,
layout: Page,
Expand Down Expand Up @@ -543,6 +546,7 @@ pub fn render_layouts(
/// * `text_to_parse` - The text to be parsed
///
/// * `collections` - Collection store of this build
#[inline]
pub fn render_snippets(
page: &Page,
text_to_parse: &str,
Expand Down Expand Up @@ -613,6 +617,7 @@ pub fn render_snippets(
/// * `snippet_context` - The context passed within the snippet call
///
/// * `collections` - Collection store of this build
#[inline]
pub fn render_snippet(
page: &Page,
snippet_path: String,
Expand Down Expand Up @@ -644,6 +649,7 @@ pub fn render_snippet(
/// # Arguments
///
/// * `snippet_call` - The snippet call to be cut up
#[inline]
pub fn get_snippet_call_portions(snippet_call: String) -> Vec<String> {
let mut call_portions: Vec<String> = vec![];
let mut current_argument: String = "".to_owned();
Expand All @@ -670,6 +676,7 @@ pub fn get_snippet_call_portions(snippet_call: String) -> Vec<String> {
/// # Arguments
///
/// * `call_portions` - A snippet call, seperated into multiple portions by spaces
#[inline]
pub fn get_snippet_keys(call_portions: &[String]) -> Vec<String> {
let mut keys: Vec<String> = vec![];
let mut current_key: String = "".to_owned();
Expand Down Expand Up @@ -701,6 +708,7 @@ pub fn get_snippet_keys(call_portions: &[String]) -> Vec<String> {
/// * `call_portions` - A snippet call, seperated into multiple portions by spaces
///
/// * `keys` - The keys of a snippet call's arguments
#[inline]
pub fn get_snippet_values(call_portions: &[String], keys: &[String]) -> Vec<String> {
let mut values: Vec<String> = vec![];
let mut current_value: String = "".to_owned();
Expand Down Expand Up @@ -753,6 +761,7 @@ pub fn get_snippet_values(call_portions: &[String], keys: &[String]) -> Vec<Stri
/// # Arguments
///
/// * `text_to_render` - The Markdown text to render into HTML
#[inline(always)]
pub fn render_markdown(text_to_render: String) -> String {
let mut markdown_options = Options::empty();
markdown_options.insert(Options::ENABLE_TABLES);
Expand All @@ -765,4 +774,4 @@ pub fn render_markdown(text_to_render: String) -> String {
html::push_html(&mut rendered_markdown, markdown_parser);

rendered_markdown
}
}
Loading

0 comments on commit 47894eb

Please sign in to comment.