From: "pelzflorian (Florian Pelz)" <pelzflorian@pelzflorian.de>
To: julien lepiller <julien@lepiller.eu>
Cc: guix-devel@gnu.org
Subject: Re: Translating to Chinese, Spanish and Japanese (and more)
Date: Tue, 6 Feb 2018 11:19:07 +0100 [thread overview]
Message-ID: <20180206101907.w3hrdtdew7ovlxco@floriannotebook> (raw)
In-Reply-To: <20180206101750.nanwvypco7tvq3ci@floriannotebook>
[-- Attachment #1.1: Type: text/plain, Size: 19 bytes --]
Forgot attachment.
[-- Attachment #1.2: 0001-page-Allow-for-creating-multiple-files-as-variants-f.patch --]
[-- Type: text/plain, Size: 3505 bytes --]
From 4a30c23a339278947db0cebbf26c80ce1585e561 Mon Sep 17 00:00:00 2001
From: Florian Pelz <pelzflorian@pelzflorian.de>
Date: Mon, 5 Feb 2018 13:08:14 +0100
Subject: [PATCH 1/2] page: Allow for creating multiple files as variants for
each page.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.16.1"
This is a multi-part message in MIME format.
--------------2.16.1
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit
* haunt/page.scm: Adapt write-page to optionally build multiple
variants and add helper function to transform file
names.
---
haunt/page.scm | 50 +++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 45 insertions(+), 5 deletions(-)
--------------2.16.1
Content-Type: text/x-patch; name="0001-page-Allow-for-creating-multiple-files-as-variants-f.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0001-page-Allow-for-creating-multiple-files-as-variants-f.patch"
diff --git a/haunt/page.scm b/haunt/page.scm
index 85b2ae6..1dfb123 100644
--- a/haunt/page.scm
+++ b/haunt/page.scm
@@ -32,6 +32,7 @@
page-file-name
page-contents
page-writer
+ variant->file-name
write-page))
(define-record-type <page>
@@ -41,10 +42,49 @@
(contents page-contents)
(writer page-writer))
-(define (write-page page output-directory)
- "Write PAGE to OUTPUT-DIRECTORY."
+(define (variant->file-name variant base-file-name)
+ (let ((variant-as-text
+ (with-output-to-string
+ (lambda ()
+ (display variant))))
+ (period-index
+ (string-rindex base-file-name #\.)))
+ (if period-index
+ (string-append
+ (string-take base-file-name
+ period-index)
+ "."
+ variant-as-text
+ "."
+ (string-drop base-file-name
+ (1+ period-index)))
+ (string-append
+ base-file-name
+ "."
+ variant-as-text))))
+
+(define* (write-page page output-directory
+ #:optional
+ variants
+ (variant-namer variant->file-name))
+ "Write PAGE to OUTPUT-DIRECTORY. If VARIANTS are given, the page
+contents may be a procedure that given a page variant returns what
+data to write. Otherwise the page contents must be the data to
+write."
+ (define (write-content-variant content-variant file-name)
+ (let ((output (string-append output-directory "/" file-name)))
+ (mkdir-p (dirname output))
+ (call-with-output-file output
+ (cut writer content-variant <>))))
(match page
(($ <page> file-name contents writer)
- (let ((output (string-append output-directory "/" file-name)))
- (mkdir-p (dirname output))
- (call-with-output-file output (cut writer contents <>))))))
+ (if (and variants (not (null? variants)) (procedure? contents))
+ (for-each
+ (lambda (variant)
+ (let ((name (variant-namer variant file-name))
+ (content-variant (contents variant)))
+ (when content-variant
+ (format #t " variant '~a'~%" name)
+ (write-contents content-variant name))))
+ variants)
+ (write-contents contents file-name)))))
--------------2.16.1--
[-- Attachment #1.3: 0002-site-Allow-specifying-variants-in-which-to-create-ea.patch --]
[-- Type: text/plain, Size: 3695 bytes --]
From 1391e8c3990ed25f9a5a09ce67ef055e975bc317 Mon Sep 17 00:00:00 2001
From: Florian Pelz <pelzflorian@pelzflorian.de>
Date: Mon, 5 Feb 2018 13:13:14 +0100
Subject: [PATCH 2/2] site: Allow specifying variants in which to create each
page.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.16.1"
This is a multi-part message in MIME format.
--------------2.16.1
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit
* haunt/site.scm: Add variants for which to create pages.
---
haunt/site.scm | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
--------------2.16.1
Content-Type: text/x-patch; name="0002-site-Allow-specifying-variants-in-which-to-create-ea.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0002-site-Allow-specifying-variants-in-which-to-create-ea.patch"
diff --git a/haunt/site.scm b/haunt/site.scm
index 48573e2..a321bbf 100644
--- a/haunt/site.scm
+++ b/haunt/site.scm
@@ -44,6 +44,7 @@
site-make-slug
site-readers
site-builders
+ site-variants
site-post-slug
build-site
@@ -52,7 +53,8 @@
(define-record-type <site>
(make-site title domain posts-directory file-filter build-directory
- default-metadata make-slug readers builders)
+ default-metadata make-slug readers builders variants
+ variant-namer)
site?
(title site-title)
(domain site-domain)
@@ -62,7 +64,9 @@
(default-metadata site-default-metadata)
(make-slug site-make-slug)
(readers site-readers)
- (builders site-builders))
+ (builders site-builders)
+ (variants site-variants)
+ (variant-namer site-variant-namer))
(define* (site #:key
(title "This Place is Haunted")
@@ -73,7 +77,9 @@
(default-metadata '())
(make-slug post-slug)
(readers '())
- (builders '()))
+ (builders '())
+ (variants '())
+ (variant-namer variant->file-name))
"Create a new site object. All arguments are optional:
TITLE: The name of the site
@@ -86,9 +92,12 @@ DEFAULT-METADATA: An alist of arbitrary default metadata for posts
whose keys are symbols
MAKE-SLUG: A procedure generating a file name slug from a post
READERS: A list of reader objects for processing posts
-BUILDERS: A list of procedures for building pages from posts"
+BUILDERS: A list of procedures for building pages from posts
+VARIANTS: Variants for which to build the site’s pages
+VARIANT-NAMER: Procedure to turn variant and file name into a new name"
(make-site title domain posts-directory file-filter build-directory
- default-metadata make-slug readers builders))
+ default-metadata make-slug readers builders variants
+ variant-namer))
(define (site-post-slug site post)
"Return a slug string for POST using the slug generator for SITE."
@@ -109,7 +118,9 @@ BUILDERS: A list of procedures for building pages from posts"
(for-each (match-lambda
((? page? page)
(format #t "writing page '~a'~%" (page-file-name page))
- (write-page page build-dir))
+ (write-page page build-dir
+ (site-variants site)
+ (site-variant-namer site)))
((? asset? asset)
(format #t "copying asset '~a' → '~a'~%"
(asset-source asset)
--------------2.16.1--
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2018-02-06 10:19 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-05 9:07 Translating to Chinese, Spanish and Japanese (and more) Pjotr Prins
2018-02-05 9:28 ` julien lepiller
2018-02-05 9:41 ` pelzflorian (Florian Pelz)
2018-02-05 12:26 ` Ricardo Wurmus
2018-02-05 14:47 ` pelzflorian (Florian Pelz)
2018-02-05 17:21 ` Ricardo Wurmus
2018-02-05 14:44 ` pelzflorian (Florian Pelz)
2018-02-06 10:17 ` pelzflorian (Florian Pelz)
2018-02-06 10:19 ` pelzflorian (Florian Pelz) [this message]
2018-03-29 10:22 ` julien lepiller
2018-04-21 15:41 ` pelzflorian (Florian Pelz)
2018-02-05 10:19 ` Ludovic Courtès
2018-02-05 10:49 ` pelzflorian (Florian Pelz)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180206101907.w3hrdtdew7ovlxco@floriannotebook \
--to=pelzflorian@pelzflorian.de \
--cc=guix-devel@gnu.org \
--cc=julien@lepiller.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.