diff options
| author | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2025-05-05 02:36:22 +0200 |
|---|---|---|
| committer | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2025-06-15 01:30:32 +0200 |
| commit | fe50a8d4faa5cbf61155a15cdb3c1caaf70558c9 (patch) | |
| tree | 621af0edf37bb8ac0bd2159fe0f6e5f9772a2f39 /website | |
| parent | 50b307b264e05bffe6c10ff438e1ac521ecfa510 (diff) | |
| download | haunt-blog-fe50a8d4faa5cbf61155a15cdb3c1caaf70558c9.tar.gz haunt-blog-fe50a8d4faa5cbf61155a15cdb3c1caaf70558c9.tar.bz2 haunt-blog-fe50a8d4faa5cbf61155a15cdb3c1caaf70558c9.zip | |
Make old WordPress URLs work.
Since people probably linked to existing WordPress articles at some point, and
might continue to do so until we replace WordPress with the website we
generate with Haunt, we need to keep the compatibility with the old articles
URLs to not break people's links.
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
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))))) |
