;;; Copyright © 2015 David Thompson ;;; Copyright © 2016 Christopher Allan Webber ;;; Copyright © 2023-2025 Denis 'GNUtoo' Carikli ;;; ;;; 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 . (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)))))