more mara tests

This commit is contained in:
Cadey Ratio 2020-09-18 17:19:14 -04:00
parent 3b475b5ac3
commit 1dfd885ae3
4 changed files with 50 additions and 44 deletions

View File

@ -8,8 +8,9 @@ date: 2020-09-18
[But if you do this thing, what about that other [But if you do this thing, what about that other
thing?](conversation://Mara/hmm) thing?](conversation://Mara/hmm)
[If you like using this, be sure to check out this other thing: [If you like using this, be sure to check out <a
https://h.christine.website](conversation://Mara/hacker) href="https://h.christine.website">this other thing</a>, it is
cool!](conversation://Mara/hacker)
[But, how does that make sense if you refrobnicated the bifrucated flopnax back [But, how does that make sense if you refrobnicated the bifrucated flopnax back
there?](conversation://Mara/wat) there?](conversation://Mara/wat)

View File

@ -1,7 +1,8 @@
use color_eyre::eyre::{Result, WrapErr}; use color_eyre::eyre::{Result, WrapErr};
use comrak::nodes::{Ast, AstNode, NodeValue}; use comrak::nodes::{Ast, AstNode, NodeValue};
use comrak::{format_html, parse_document, Arena, ComrakOptions}; use comrak::{format_html, parse_document, markdown_to_html, Arena, ComrakOptions};
use std::cell::RefCell; use std::cell::RefCell;
use crate::templates::Html;
use url::Url; use url::Url;
pub fn render(inp: &str) -> Result<String> { pub fn render(inp: &str) -> Result<String> {
@ -31,13 +32,16 @@ pub fn render(inp: &str) -> Result<String> {
let parent = node.parent().unwrap(); let parent = node.parent().unwrap();
node.detach(); node.detach();
let mut message = vec![]; let mut message = vec![];
format_html(node.first_child().unwrap(), &options, &mut message)?; for child in node.children() {
format_html(child, &options, &mut message)?;
}
let message = std::str::from_utf8(&message)?; let message = std::str::from_utf8(&message)?;
let message = markdown_to_html(message, &options);
let mood = without_first(u.path()); let mood = without_first(u.path());
let name = u.host_str().unwrap_or("Mara"); let name = u.host_str().unwrap_or("Mara");
let mut html = vec![]; let mut html = vec![];
crate::templates::mara(&mut html, mood, name, message)?; crate::templates::mara(&mut html, mood, name, Html(message))?;
let new_node = let new_node =
arena.alloc(AstNode::new(RefCell::new(Ast::new(NodeValue::HtmlInline(html))))); arena.alloc(AstNode::new(RefCell::new(Ast::new(NodeValue::HtmlInline(html)))));

View File

@ -62,61 +62,62 @@
<p>Tags: @for tag in post.front_matter.tags.as_ref().unwrap() { <code>@tag</code> }</p> <p>Tags: @for tag in post.front_matter.tags.as_ref().unwrap() { <code>@tag</code> }</p>
} }
<script> <p>The art for Mara was drawn by <a href="https://selic.re/">Selicre</a>.</p>
// The actual function. Set this as an onclick function for your "Share on Mastodon" button <script>
function share_on_mastodon() @{ // The actual function. Set this as an onclick function for your "Share on Mastodon" button
function share_on_mastodon() @{
// Prefill the form with the user's previously-specified Mastodon instance, if applicable // Prefill the form with the user's previously-specified Mastodon instance, if applicable
var default_url = localStorage['mastodon_instance']; var default_url = localStorage['mastodon_instance'];
// If there is no cached instance/domain, then insert a "https://" with no domain at the start of the prompt. // If there is no cached instance/domain, then insert a "https://" with no domain at the start of the prompt.
if (!default_url) if (!default_url)
default_url = "https://"; default_url = "https://";
var instance = prompt("Enter your instance's address: (ex: https://linuxrocks.online)", default_url); var instance = prompt("Enter your instance's address: (ex: https://linuxrocks.online)", default_url);
if (instance) @{ if (instance) @{
// Handle URL formats // Handle URL formats
if ( !instance.startsWith("https://") && !instance.startsWith("http://") ) if ( !instance.startsWith("https://") && !instance.startsWith("http://") )
instance = "https://" + instance; instance = "https://" + instance;
// get the current page's url // get the current page's url
var url = window.location.href; var url = window.location.href;
// get the page title from the og:title meta tag, if it exists.
var title = document.querySelectorAll('meta[property="og:title"]')[0].getAttribute("content");
// Otherwise, use the <title> tag as the title
if (!title) var title = document.getElementsByTagName("title")[0].innerHTML;
// Handle slash
if ( !instance.endsWith("/") )
instance = instance + "/";
// Cache the instance/domain for future requests // get the page title from the og:title meta tag, if it exists.
localStorage['mastodon_instance'] = instance; var title = document.querySelectorAll('meta[property="og:title"]')[0].getAttribute("content");
// Hashtags // Otherwise, use the <title> tag as the title
var hashtags = "#blogpost"; if (!title) var title = document.getElementsByTagName("title")[0].innerHTML;
@if post.front_matter.series.is_some() { // Handle slash
hashtags += "#@post.front_matter.series.as_ref().unwrap()"; if ( !instance.endsWith("/") )
} instance = instance + "/";
@if post.front_matter.tags.is_some() { // Cache the instance/domain for future requests
hashtags += "@for tag in post.front_matter.tags.as_ref().unwrap() { #@tag }"; localStorage['mastodon_instance'] = instance;
}
// Tagging users, such as offical accounts or the author of the post // Hashtags
var author = "@@cadey@@mst3k.interlinked.me"; var hashtags = "#blogpost";
// Create the Share URL @if post.front_matter.series.is_some() {
// https://someinstance.tld/share?text=URL%20encoded%20text hashtags += "#@post.front_matter.series.as_ref().unwrap()";
mastodon_url = instance + "share?text=" + encodeURIComponent(title + "\n\n" + url + "\n\n" + hashtags + " " + author); }
// Open a new window at the share location @if post.front_matter.tags.is_some() {
window.open(mastodon_url, '_blank'); hashtags += "@for tag in post.front_matter.tags.as_ref().unwrap() { #@tag }";
}
// Tagging users, such as offical accounts or the author of the post
var author = "@@cadey@@mst3k.interlinked.me";
// Create the Share URL
// https://someinstance.tld/share?text=URL%20encoded%20text
mastodon_url = instance + "share?text=" + encodeURIComponent(title + "\n\n" + url + "\n\n" + hashtags + " " + author);
// Open a new window at the share location
window.open(mastodon_url, '_blank');
@}
@} @}
@}
</script> </script>
@:footer_html() @:footer_html()

View File

@ -1,4 +1,4 @@
@(mood: &str, character: &str, message: &str) @(mood: &str, character: &str, message: Html<String>)
<div class="grid conversation"> <div class="grid conversation">
<div class="cell -2of12"> <div class="cell -2of12">
<div class="content"> <div class="content">
@ -9,6 +9,6 @@
</div> </div>
</div> </div>
<div class="cell -10of12"> <div class="cell -10of12">
<div class="content"><p><b>@character</b><br></p><blockquote>@message</blockquote></div> <div class="content"><p><b>@character</b><br></p>@message</div>
</div> </div>
</div> </div>