Commit aa21c766 authored by Luc Didry's avatar Luc Didry

Add Markdown support (need Pandoc to work)

parent e608b727
Pipeline #24137 passed with stages
in 52 seconds
......@@ -7,6 +7,7 @@ pages:
- local
- cache
script:
- apt-get -qq update && apt-get -qq -y install pandoc
- carton install
- carton exec ./build.pl
artifacts:
......
Revision history for Last
0.3.0 2017-09-30
- Add Markdown support (need Pandoc to work)
0.2.0 2017-09-24
- Use API to fetch toots
- Video attachments handling
......
......@@ -18,6 +18,8 @@ To add new toots, add them in `urls` and then commit and push.
If you want to change the aspect of the generated web page and epub, you can either modify the default theme (you'll have to handle merge conflicts when you upgrade your repo from upstream) or copy the default theme to a new directory in `themes/`, modify it and choose this new theme in the configuration file.
If you want to handle [Markdown syntax](https://daringfireball.net/projects/markdown/syntax) in your toots, you'll need to install pandoc.
## Example
Please, go to <https://luc.frama.io/last/> to see how it looks.
......
......@@ -19,6 +19,7 @@ use File::Path qw(rmtree);
use FindBin qw($Bin);
use Text::Slugify 'slugify';
use XML::Atom::SimpleFeed;
use Pandoc;
use POSIX;
# Get config
......@@ -27,9 +28,10 @@ my $ua = Mojo::UserAgent->new();
my $config = $m->plugin(Config => {
file => File::Spec->catfile($Bin, 'last.conf'),
default => {
theme => 'default',
sort => 1,
license => '',
theme => 'default',
sort => 1,
license => '',
markdown => 0,
}
});
my $theme = $config->{theme};
......@@ -264,6 +266,22 @@ $urls->each(
my $attachments2 = (scalar @imgs2) ? "<div><p>@imgs2</p></div>" : '';
## Mix date, time, content and attachments
if ($config->{markdown} && $content =~ m#([^%])?%md#) {
$content =~ s#%%md#%%LAST_MARKDOWN%%#g;
$content =~ s#%md##g;
$content =~ s#%%LAST_MARKDOWN%%#%md#g;
# Images
$content =~ s#!\[(.*?)\]\(<a href="([^"]*)".*?</a>\)#![$1]($2)#gm;
# Links with text
$content =~ s#\[(.*?)\]\(<a href="([^"]*)".*?</a>\)#[$1]($2)#gm;
# Links
$content =~ s#&lt;<a href="([^"]*)".*?</a>&gt;#<$1>#gm;
my $md;
my $html = encode('UTF-8', $content);
pandoc -f => 'markdown', -t => 'html', { in => \$html, out => \$md };
say $md;
$content = decode('UTF-8', $md);
}
$content =~ s#<p></p>|</br>##g;
$content =~ s#<br>#<br />#g;
my $append = "\n <article><a href=\"#$id\"><h3 id=\"$id\">$date <span style=\"font-size: 0.5em;\">$time</span></h3></a>$content$attachments<div><a href=\"$i\"><em>Source</em></a></div></article><hr>\n";
......
......@@ -7,3 +7,4 @@ requires 'File::Copy::Recursive';
requires 'XML::Atom::SimpleFeed';
requires 'Archive::Zip';
requires 'Text::Slugify';
requires 'Pandoc';
......@@ -656,6 +656,13 @@ DISTRIBUTIONS
perl 5.008
strict 0
warnings 0
File-Which-1.22
pathname: P/PL/PLICEASE/File-Which-1.22.tar.gz
provides:
File::Which 1.22
requirements:
ExtUtils::MakeMaker 0
perl 5.006
IO-Socket-SSL-2.049
pathname: S/SU/SULLR/IO-Socket-SSL-2.049.tar.gz
provides:
......@@ -673,6 +680,14 @@ DISTRIBUTIONS
Mozilla::CA 0
Net::SSLeay 1.46
Scalar::Util 0
IPC-Run3-0.048
pathname: R/RJ/RJBS/IPC-Run3-0.048.tar.gz
provides:
IPC::Run3 0.048
requirements:
ExtUtils::MakeMaker 0
Test::More 0.31
Time::HiRes 0
MRO-Compat-0.13
pathname: H/HA/HAARG/MRO-Compat-0.13.tar.gz
provides:
......@@ -945,6 +960,16 @@ DISTRIBUTIONS
XSLoader 0
strict 0
warnings 0
Pandoc-0.6.0
pathname: V/VO/VOJ/Pandoc-0.6.0.tar.gz
provides:
Pandoc 0.006000
Pandoc::Version 0.006000
requirements:
File::Which 1.11
IPC::Run3 0
Module::Build::Tiny 0.039
perl 5.010
Params-ValidationCompiler-0.24
pathname: D/DR/DROLSKY/Params-ValidationCompiler-0.24.tar.gz
provides:
......
# vim:set sw=4 ts=4 sts=4 ft=perl expandtab:
{
# Mandatory, your name
## Mandatory, your name
author => 'Luc Didry',
# Mandatory, the title of the page and the epub
## Mandatory, the title of the page and the epub
title => 'Last: Let\'s Aggregate Superb Toots',
# Mandatory, language of the toots
## Mandatory, language of the toots
language => 'fr',
# Optional, sort the toots' list before fetching them
## Optional, sort the toots' list before fetching them
# Default is 0 (= no)
sort => 0,
# Optional, process the toots' list in reverse order for the page
## Optional, process the toots' list in reverse order for the page
# Note that the reversing is done after sort if sort is enabled
# Default value is 0 (= no)
reverse => 0,
# Mandatory, where you will publish the page
## Mandatory, where you will publish the page
public_url => 'https://luc.frama.io/last/',
# Optional, what theme to use.
## Optional, what theme to use.
# Default value is 'default'
theme => 'default',
# Pagination
## Optional, interpret toots as markdown if they contains %md
# You will need to install pandoc to use that option!
# Defautl value is 0 (= no)
#markdown => 0,
## Pagination
# How many toots will be displayed per HTML page?
# 0 means unlimited toots on one page
# Optional, default is 0
#pagination => 0,
# Optional, what license do you use?
## Optional, what license do you use?
# If you choose one of these: cc-0, cc-by-nc-nd, cc-by-nc-sa, cc-by-nd, cc-by, cc-by-sa.png public-domain,
# a badge will be displayed
# No default
license => 'cc-0',
# Mandatory, the toots you want to fetch
## Mandatory, the toots you want to fetch
urls => [
'https://framapiaf.org/@framasky/1095291',
'https://framapiaf.org/@framasky/1095753',
'https://framapiaf.org/@framasky/1095869',
'https://framapiaf.org/@framasky/1096170',
'https://framapiaf.org/@framasky/2858634',
'https://framapiaf.org/@framasky/2859180',
'https://framapiaf.org/@framasky/2859260',
],
# Optional, the hashtags you want to hide
## Optional, the hashtags you want to hide
# No default
#hidden_tags => [
# 'mercredifiction',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment