From d96f0eae88b124566641aa42a951a8cca46864e0 Mon Sep 17 00:00:00 2001 From: Arnaud Legrand Date: Fri, 22 Mar 2019 09:06:18 +0100 Subject: [PATCH] Have a single script to handle both org and md conversion --- .gitlab-ci.yml | 16 ++++++---------- bin/pandoc_fixer.pl | 44 +++++++++++++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 161cdb8..5c5bff0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,19 +3,15 @@ pages: stage: deploy script: - pandoc --version - - pandoc --help + # - pandoc --help # - pandoc --list-input-formats # Broken as pandoc dates from 2013 on this image! :( - - for file in $(find -name "*.md"); do - pandoc -s -f gfm -t html -o ${file%.*}.html $file && echo "Exported ${file%.*}.html" && echo "
  • ${file%.*}.html
  • " >> index.html || echo "ERROR $file"; - bin/pandoc_fixer.pl ${file} > ${file}.new; - mv ${file}.new ${file%.*}.html; + - for file in $(find -name "*.md") $(find -name "*.org"); do + bin/pandoc_fixer.pl ${file}; + mkdir -p public/`dirname ${file}` + mv ${file%.*}.html public/`dirname ${file}` done - # The next part is broken because pandoc is way too old on this image :( - # - for file in $(find -name "*.org"); do - # pandoc -s -f org -t html -o ${file%.*}.html $file && echo "Exported ${file%.*}.html" || echo "ERROR $file"; - # done - shopt -s extglob - - mv !(public) public + # - mv !(public) public artifacts: paths: - public diff --git a/bin/pandoc_fixer.pl b/bin/pandoc_fixer.pl index 9b9ded1..61af3ff 100755 --- a/bin/pandoc_fixer.pl +++ b/bin/pandoc_fixer.pl @@ -1,34 +1,48 @@ #!/usr/bin/perl -w use strict; -if($#ARGV!=0) { - die "Usage: pandox_fixer.pl input.md"; -} +my($usage) = "Usage: pandox_fixer.pl input.md"; +($#ARGV==0) or die $usage; + my($input)=shift(@ARGV); -if(!($input =~ /.md$/)) { - die "Usage: pandox_fixer.pl input.md"; -} -my($line); +########### Git date ################# my($gitdate)=`git log $input | grep Date | head -n 1`; chomp($gitdate); $gitdate =~ s/Date: *//g; $gitdate =~ s/\s*\+.*$//g; - -$input =~ s/.md/.html/; +########### Input file ############### +my($type) = ""; +my($output) = $input; +if($input =~ /.md$/) { + $type = "gfm"; + $output =~ s/.md$/.html/; +} elsif ($input =~ /.org$/) { + $type = "org"; + $output =~ s/.org$/.html/; +} else { + die "Usage: pandox_fixer.pl input.md"; +} +my($output_temp) = $output."tmp"; -open INPUT, $input or die; +########### URL Fixing ############### my($input_path)=$input; $input_path =~ s|/[^/]*$||g; -# print $input."\n\n"; - my($url_path) = "https://gitlab.inria.fr/learninglab/mooc-rr/mooc-rr-ressources/raw/master/".$input_path; - my($gitlab_origin)= "https://gitlab.inria.fr/learninglab/mooc-rr/mooc-rr-ressources/blob/master/"; -while(defined($line=)) { +########### Pandoc ################# + +print "Exporting $input\n"; +my($pandoc_output) = `LANG=C ; pandoc -s -f $type -t html -o $output_temp $input`; + +open INPUT, $output_temp or die; +open OUTPUT, "> ".$output or die; + + +while(defined(my $line=)) { # $line =~ s|https://gitlab.inria.fr/learninglab/|https://learninglab.gitlabpages.inria.fr/|g; ## Not such a good idea! if($input=~ /_fr.html/) { $line =~ s||Les sources de ce document sont disponibles sur gitlab.|g; @@ -48,6 +62,6 @@ while(defined($line=)) { # $line = "\t".$line; # } if($line =~ /

    AUTHOR:/) { next; } - print $line; + print OUTPUT $line; } -- 2.18.1