From mboxrd@z Thu Jan 1 00:00:00 1970 From: "pelzflorian (Florian Pelz)" Subject: Re: Translating to Chinese, Spanish and Japanese (and more) Date: Tue, 6 Feb 2018 11:19:07 +0100 Message-ID: <20180206101907.w3hrdtdew7ovlxco@floriannotebook> References: <20180205090716.GB10165@thebird.nl> <30df6bb24a385c945d261feb5f2f99d2@lepiller.eu> <20180205094129.efgxn7nucoj3kwsf@floriannotebook> <20180205144429.rza5xovsei6arfeg@floriannotebook> <20180206101750.nanwvypco7tvq3ci@floriannotebook> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="uxwm6ut5d4uyl453" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43500) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ej0LI-0005bU-RW for guix-devel@gnu.org; Tue, 06 Feb 2018 05:19:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ej0LE-00065y-KD for guix-devel@gnu.org; Tue, 06 Feb 2018 05:19:12 -0500 Received: from pelzflorian.de ([5.45.111.108]:49948 helo=mail.pelzflorian.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ej0LE-00064i-55 for guix-devel@gnu.org; Tue, 06 Feb 2018 05:19:08 -0500 Content-Disposition: inline In-Reply-To: <20180206101750.nanwvypco7tvq3ci@floriannotebook> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: julien lepiller Cc: guix-devel@gnu.org --uxwm6ut5d4uyl453 Content-Type: multipart/mixed; boundary="xzb4pdccbcjwoeyp" Content-Disposition: inline --xzb4pdccbcjwoeyp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Forgot attachment. --xzb4pdccbcjwoeyp Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-page-Allow-for-creating-multiple-files-as-variants-f.patch" Content-Transfer-Encoding: quoted-printable =46rom 4a30c23a339278947db0cebbf26c80ce1585e561 Mon Sep 17 00:00:00 2001 =46rom: Florian Pelz 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=3D"------------2.16.1" This is a multi-part message in MIME format. --------------2.16.1 Content-Type: text/plain; charset=3DUTF-8; format=3Dfixed 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=3D"0001-page-Allow-for-creating-multiple-f= iles-as-variants-f.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename=3D"0001-page-Allow-for-creating-m= ultiple-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)) =20 (define-record-type @@ -41,10 +42,49 @@ (contents page-contents) (writer page-writer)) =20 -(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 (($ 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-- --xzb4pdccbcjwoeyp Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="0002-site-Allow-specifying-variants-in-which-to-create-ea.patch" Content-Transfer-Encoding: quoted-printable =46rom 1391e8c3990ed25f9a5a09ce67ef055e975bc317 Mon Sep 17 00:00:00 2001 =46rom: Florian Pelz 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=3D"------------2.16.1" This is a multi-part message in MIME format. --------------2.16.1 Content-Type: text/plain; charset=3DUTF-8; format=3Dfixed 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=3D"0002-site-Allow-specifying-variants-in-= which-to-create-ea.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename=3D"0002-site-Allow-specifying-var= iants-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 =20 @@ -52,7 +53,8 @@ =20 (define-record-type (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)) =20 (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: =20 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=E2=80=99s 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)) =20 (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' =E2=86=92 '~a'~%" (asset-source asset) --------------2.16.1-- --xzb4pdccbcjwoeyp-- --uxwm6ut5d4uyl453 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEwRjGsqAMqXB4uw3y3T6EbElHBVsFAlp5gRsACgkQ3T6EbElH BVtVUBAAuah0o2JPzw1rAS2mHLALxjFWFp3/6Nw0IkIYUJUUMvEVxL3Bvo52oH6X pFC71CG1JxUX8aCqcHDzk2sGjzqLeuUPtdqXBt/OnsHIa55Hel9Xq0ki5yHz/Zri c0EPdi24SJ22eprGxEXZ9sz/coT1av9gSH7c+BGus/hUTD0BcxEOjUTukG8REh9V 5Z7nyKLG/smxZ41EcaP0//mLyck225E64rZUVWXnCcZVNJvbPPkswnGN3grCRTkP 3o2eeOnOd6M9KQLoNw/tGc2cR3K/EtCY1UlDOTHG/dHG+F8J9w+iPHHfS4WlLBpG kDrIFKHrCC5C9ewv5zKINFSKj3kGP0opJulM5qUOBJimB13/g5tJJ9j43eq37KGK MWMdbawQT4ObiVegCsw68mh8PFZeS59lprHhPwsKEfecepNS/9TvpMgycvEaMKOa 1s3pz8mCwzbrIujrPId5UV+RB2HThNWt/09kOUdoo4YLW2h4lPXSSFAXI76Rb3yY NX4tPr6IjTS04wQWBEV6oUYEBisHaNlL47B/DfjFcqzCvH+mSpZ4IqyR0oUbetdE 3wYKJV9+Lyvfz0FAzm3lrBr+OcW7GO4IcpWn6BlCTq25unCPMExyqU3QCzNYbXIC hAvqcJmDOKE0s7UA0jAfHL3ertKXgwHdY5KiDvbR4kKYL4sfJlY= =yHGs -----END PGP SIGNATURE----- --uxwm6ut5d4uyl453--