blob: 19c80764ef761cffaceda47bab505acbff90892d (
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
|
;;; Copyright © 2015 David Thompson <davet@gnu.org>
;;; Copyright © 2016 Christopher Allan Webber <cwebber@dustycloud.org>
;;; Copyright © 2023-2025 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
;;;
;;; This file is based on haunt/builder/blog.scm,
;;; haunt/reader/commonmark.scm and tests/post.scm and from Haunt
;;; 2.6.0.
;;;
;;; This file is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published
;;; by the Free Software Foundation; either version 3 of the License,
;;; or (at your option) any later version.
;;;
;;; Haunt is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;;; General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with Haunt. If not, see <http://www.gnu.org/licenses/>.
(define-module (modules builders wordpress-compatible-links)
#:use-module (haunt builder redirects)
#:use-module (ice-9 rdelim)
#:export (make-wordpress-compatible-links))
(fluid-set! %default-port-encoding "UTF-8")
(define (parse-line line)
(define parts (string-split line #\/))
(define year (list-ref parts 3))
(define month (list-ref parts 4))
(define page (list-ref parts 5))
(define input
(string-append "/" year "/" month "/" page "/index.html"))
(define output
(string-append "../../../" page ".html"))
`((,input ,output)))
(define (make-read-file results)
(define (read-file port)
(define line (read-line port))
(if (not (eof-object? line))
((lambda _
(set! results (append results (parse-line line)))
(read-file port)))
results))
read-file)
(define (make-wordpress-compatible-links path)
(redirects (call-with-input-file path (make-read-file (list)))))
|