aboutsummaryrefslogtreecommitdiff
path: root/src/tmpl/nag.rs
blob: 0fb8496349fa1c2f49ebf559e71144f6848a7802 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use crate::post::Post;
use lazy_static::lazy_static;
use maud::{html, Markup};
use regex::Regex;

// XXX(S): needed because release builds need this
#[allow(unused)]
use chrono::prelude::*;

lazy_static! {
    static ref LOBSTERS: Regex = Regex::new(r#"^https?://lobste.rs"#).unwrap();
    static ref HACKER_NEWS: Regex = Regex::new(r#"^https?://news.ycombinator.com"#).unwrap();
}

#[cfg(debug_assertions)]
pub fn referer(_: &Post, _: Option<String>) -> Markup {
    html! {
        .warning {
            "This is a development instance of xesite. Things here are probably unfinished or in drafting. Don't take anything here super seriously. If you want to share this to an online aggregator, please don't. Drafts are not finalized yet for a reason. Please don't be the reason I need to implement more advanced security than just obscurity."
        }
        br;
    }
}

#[cfg(not(debug_assertions))]
pub fn referer(post: &Post, referer: Option<String>) -> Markup {
    use xesite_templates::conv as xeblog_conv;

    if referer.is_none() {
        return xesite_templates::advertiser_nag(None);
    }

    let referer = referer.unwrap();

    if Utc::now().date_naive().num_days_from_ce() < post.date.num_days_from_ce() {
        return html! {};
    }

    if HACKER_NEWS.is_match(&referer) {
        return xesite_templates::advertiser_nag(Some(xeblog_conv(
            "Mara".into(),
            "hacker".into(),
            html! {
                "Hello. Before commenting about the author, please read "
                a href="/pronouns" {"this page"}
                " that explains the pronouns that you should be using. tl;dr: the author of this website is NOT male. Please do not use \"he\" or \"him\" when referring to the author."
            },
        )));
    }

    if LOBSTERS.is_match(&referer) {
        return xeblog_conv(
            "Mara".into(),
            "happy".into(),
            html! {
                "Hey, thanks for reading Lobsters! We've disabled the ads to thank you for choosing to use a more ethical aggregator."
            },
        );
    }

    xesite_templates::advertiser_nag(None)
}

#[cfg(debug_assertions)]
pub fn prerelease(_: &Post) -> Markup {
    html! {}
}

#[cfg(not(debug_assertions))]
pub fn prerelease(post: &Post) -> Markup {
    use chrono::prelude::*;
    use xesite_templates::conv as xeblog_conv;

    if Utc::now().date_naive().num_days_from_ce() < post.date.num_days_from_ce() {
        html! {
            .warning {
                (xeblog_conv("Mara".into(), "hacker".into(), html!{
                    "Hey, this post is set to go live on "
                    (format!("{}", post.detri()))
                    " UTC. Right now you are reading a pre-publication version of this post. Please do not share this on social media. This post will automatically go live for everyone on the intended publication date. If you want access to these posts, please join the "
                    a href="https://www.patreon.com/cadey" { "Patreon" }
                    ". It helps me afford the copyeditor that I contract for the technical content I write."
                    br;
                }))
            }
        }
    } else {
        html! {}
    }
}