Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get started & Hero section #89

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
444 changes: 444 additions & 0 deletions example/content/2024-10-24-getting-started.md

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions example/content/404.md

This file was deleted.

7 changes: 7 additions & 0 deletions example/content/_404.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Cat not found
---

<div style="text-align:center;">
<img src="https://http.cat/images/404.jpg">
</div>
17 changes: 17 additions & 0 deletions example/content/_hero.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div class="grid" style="display: flex;">

<div style="align-content: center;">
<img src="https://github.com/rochacbruno/marmite/raw/main/assets/_resized/logo_160x120.png" width="100" align="left" >
</div>

<div>

>>>
I'm a big user of other SSGs but it is frequently frustrating that it takes so much setup to get started.
Just having a directory of markdown files and running a single command sounds really useful.
&mdash; Michael, marmite user.
>>>

</div>

</div>
7 changes: 7 additions & 0 deletions example/content/customizing-templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ There are 6 templates inside the `templates` folder, each adds more data to cont
- Renders grouped information such as `tag/sometag.html` and `archive/2024.html`
- adds `title:str`, `group_content: [[group, [Content]]]`, `current_page: str`

Include templates:

- pagination.html
- Render the pagination controls
- comments.html
- Render the comment box

When customizing the templates you can create new templates to use as `include` or `macro`
but the 4 listed above are required.

Expand Down
3 changes: 0 additions & 3 deletions example/content/hosting.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,14 @@ jobs:
run: marmite . site --debug

- name: Setup Pages
if: github.event_name == 'push'
uses: actions/configure-pages@v5

- name: Upload artifact
if: github.event_name == 'push'
uses: actions/upload-pages-artifact@v3
with:
path: 'site'

- name: Deploy to GitHub Pages
if: github.event_name == 'push'
id: deployment
uses: actions/deploy-pages@v4
```
Expand Down
Binary file added example/content/media/screenshots/about.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/content/media/screenshots/config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/content/media/screenshots/custom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/content/media/screenshots/hero.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/content/media/screenshots/index.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/content/media/screenshots/media.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/content/media/screenshots/tags.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions example/static/marmite.css
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,18 @@ pre:has(> code.language-mermaid) {
.pagination nav li a {
font-size: 2rem;
}

.data-tags-footer {
padding: 0;
}
.data-tags-footer .content-date {
margin-left: .5rem;
}

.footer-content div {
text-align: center;
}

.hero article {
overflow: auto;
}
10 changes: 2 additions & 8 deletions example/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ <h2><a href="./index.html" class="contrast">{{ site.name }}</a></h2>
{% endif %}
</li>
{% endfor %}
<li><a href="#" id="theme-toggle" class="secondary">&#9789;</a></li>
<div class="underline"></div>
</ul>
</nav>
Expand All @@ -46,14 +47,7 @@ <h2><a href="./index.html" class="contrast">{{ site.name }}</a></h2>
{% block main -%}{%- endblock %}
</section>
<footer class="footer-content">
<nav>
<ul>
<li>{{ site.footer | safe }}</li>
</ul>
<ul>
<li><a href="#" id="theme-toggle" class="secondary">&#9789;</a></li>
</ul>
</nav>
{{ site.footer | safe }}
</footer>
</main>
{%- block tail %}
Expand Down
4 changes: 2 additions & 2 deletions example/templates/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
<article>
<div class="content-html">{{ content.html | safe }}</div>
{% if content.date %}
<footer>
<span class="content-date"> {{ content.date | date(format="%v") }}</span>
<footer class="data-tags-footer">
<span class="content-date"> {{ content.date | date(format="%b %e, %Y") }}</span>
<ul class="content-tags overflow-auto">
{% for tag in content.tags %}
<li><a href="./tag-{{ tag | trim | slugify }}.html">{{ tag }}</a></li>
Expand Down
11 changes: 9 additions & 2 deletions example/templates/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@
<article><strong> {{ title }} </strong></article>
</div>
{% endif %}
{% if hero is defined and current_page == "index.html" %}
<div class="hero">
<article>
{{hero}}
</article>
</div>
{% endif %}
<div class="content-list">
{%- for content in content_list %}
<article class="content-list-item">
<h2 class="content-title"><a href="./{{content.slug}}.html">{{ content.title | capitalize }}</a></h2>
<p class="content-excerpt">{{ content.html | striptags | truncate(length=100, end="...") }}</p>
{% if content.date -%}
<footer class="">
<span class="content-date">{{ content.date | date(format="%v") }}</span>
<footer class="data-tags-footer">
<span class="content-date">{{ content.date | date(format="%b %e, %Y") }}</span>
{% if content.tags -%}
<ul class="content-tags overflow-auto">
{% for tag in content.tags | slice(end=3) -%}
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn default_url() -> String {
}

fn default_footer() -> String {
r#"<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC-BY_NC-SA</a> | Site generated with <a href="https://github.com/rochacbruno/marmite">Marmite</a>"#.to_string()
r#"<div>Site generated with <a href="https://github.com/rochacbruno/marmite">Marmite</a> | <small><a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC-BY_NC-SA</a></small></div>"#.to_string()
}

fn default_pagination() -> usize {
Expand Down
90 changes: 36 additions & 54 deletions src/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,26 @@ use frontmatter_gen::{extract, Frontmatter};
use std::fs;
use std::path::Path;

pub fn process_file(
path: &Path,
site_data: &mut Data,
use_filename_as_slug: bool,
) -> Result<(), String> {
let file_content = fs::read_to_string(path).map_err(|e| e.to_string())?;
let (frontmatter, markdown) = parse_front_matter(&file_content)?;
let mut options = ComrakOptions::default();
pub fn process_file(path: &Path, site_data: &mut Data) -> Result<(), String> {
let content = get_content(path)?;

// TODO: Make the following options configurable?
options.render.unsafe_ = true; // Allow raw html
options.render.ignore_empty_links = true;
options.render.figure_with_caption = true;
// options.render.escape = false;
// options.render.full_info_string = true;
options.extension.tagfilter = false;
options.extension.strikethrough = true; // ~~text~~
options.extension.table = true;
options.extension.autolink = true;
options.extension.tasklist = true; // - [ ] item
options.extension.footnotes = true; // note[^`1]
options.extension.description_lists = true;
options.extension.multiline_block_quotes = true; // >>>\ntext\n>>>
options.extension.underline = true; // __under__
options.extension.spoiler = true; // this is ||secret|| (depends on css)
options.extension.greentext = true; // >not a quote
options.extension.shortcodes = true; // >not a quote
options.extension.header_ids = Some("tos-".to_string());

// The following 3 options breaks MathJax on themes
// options.extension.superscript = true; // 3^2^
// options.extension.math_dollars = true; // depends on css
// options.extension.math_code = true; // depends on css

let html = markdown_to_html(markdown, &options);
if content.date.is_some() {
site_data.posts.push(content);
} else {
site_data.pages.push(content);
}
Ok(())
}

pub fn get_content(path: &Path) -> Result<Content, String> {
let file_content = fs::read_to_string(path).map_err(|e| e.to_string())?;
let (frontmatter, markdown) = parse_front_matter(&file_content)?;
let html = get_html(markdown);
let title = get_title(&frontmatter, markdown);
let tags = get_tags(&frontmatter);
let slug = {
if use_filename_as_slug {
path.file_name()
.expect("Error on getting file name")
.to_str()
.expect("Error on converting file name to string")
.to_string()
.replace(".md", "")
} else {
get_slug(&frontmatter, path)
}
};
let slug = get_slug(&frontmatter, path);
let date = get_date(&frontmatter, path);

let extra = frontmatter.get("extra").map(std::borrow::ToOwned::to_owned);

let content = Content {
title,
slug,
Expand All @@ -67,13 +33,29 @@ pub fn process_file(
date,
extra,
};
Ok(content)
}

if date.is_some() {
site_data.posts.push(content);
} else {
site_data.pages.push(content);
}
Ok(())
pub fn get_html(markdown: &str) -> String {
let mut options = ComrakOptions::default();
options.render.unsafe_ = true;
options.render.ignore_empty_links = true;
options.render.figure_with_caption = true;
options.extension.tagfilter = false;
options.extension.strikethrough = true;
options.extension.table = true;
options.extension.autolink = true;
options.extension.tasklist = true;
options.extension.footnotes = true;
options.extension.description_lists = true;
options.extension.multiline_block_quotes = true;
options.extension.underline = true;
options.extension.spoiler = true;
options.extension.greentext = true;
options.extension.shortcodes = true;
options.extension.header_ids = Some("tos-".to_string());

markdown_to_html(markdown, &options)
}

fn parse_front_matter(content: &str) -> Result<(Frontmatter, &str), String> {
Expand Down
Loading