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
thing?](conversation://Mara/hmm)
[If you like using this, be sure to check out this other thing:
https://h.christine.website](conversation://Mara/hacker)
[If you like using this, be sure to check out <a
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
there?](conversation://Mara/wat)

View File

@ -1,7 +1,8 @@
use color_eyre::eyre::{Result, WrapErr};
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 crate::templates::Html;
use url::Url;
pub fn render(inp: &str) -> Result<String> {
@ -31,13 +32,16 @@ pub fn render(inp: &str) -> Result<String> {
let parent = node.parent().unwrap();
node.detach();
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 = markdown_to_html(message, &options);
let mood = without_first(u.path());
let name = u.host_str().unwrap_or("Mara");
let mut html = vec![];
crate::templates::mara(&mut html, mood, name, message)?;
crate::templates::mara(&mut html, mood, name, Html(message))?;
let new_node =
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>
}
<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
function share_on_mastodon() @{
<script>
// 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
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 (!default_url)
default_url = "https://";
default_url = "https://";
var instance = prompt("Enter your instance's address: (ex: https://linuxrocks.online)", default_url);
if (instance) @{
// Handle URL formats
if ( !instance.startsWith("https://") && !instance.startsWith("http://") )
instance = "https://" + instance;
// Handle URL formats
if ( !instance.startsWith("https://") && !instance.startsWith("http://") )
instance = "https://" + instance;
// get the current page's url
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 + "/";
// get the current page's url
var url = window.location.href;
// Cache the instance/domain for future requests
localStorage['mastodon_instance'] = instance;
// get the page title from the og:title meta tag, if it exists.
var title = document.querySelectorAll('meta[property="og:title"]')[0].getAttribute("content");
// Hashtags
var hashtags = "#blogpost";
// Otherwise, use the <title> tag as the title
if (!title) var title = document.getElementsByTagName("title")[0].innerHTML;
@if post.front_matter.series.is_some() {
hashtags += "#@post.front_matter.series.as_ref().unwrap()";
}
// Handle slash
if ( !instance.endsWith("/") )
instance = instance + "/";
@if post.front_matter.tags.is_some() {
hashtags += "@for tag in post.front_matter.tags.as_ref().unwrap() { #@tag }";
}
// Cache the instance/domain for future requests
localStorage['mastodon_instance'] = instance;
// Tagging users, such as offical accounts or the author of the post
var author = "@@cadey@@mst3k.interlinked.me";
// Hashtags
var hashtags = "#blogpost";
// 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);
@if post.front_matter.series.is_some() {
hashtags += "#@post.front_matter.series.as_ref().unwrap()";
}
// Open a new window at the share location
window.open(mastodon_url, '_blank');
@if post.front_matter.tags.is_some() {
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>
@: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="cell -2of12">
<div class="content">
@ -9,6 +9,6 @@
</div>
</div>
<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>