diff options
Diffstat (limited to 'website')
| -rw-r--r-- | website/builders/wordpress-compatible-links.scm | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/website/builders/wordpress-compatible-links.scm b/website/builders/wordpress-compatible-links.scm new file mode 100644 index 0000000..27be3ac --- /dev/null +++ b/website/builders/wordpress-compatible-links.scm @@ -0,0 +1,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 (website 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))))) |
