lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Getting download sizes right: proof of concept


From: David Kastrup
Subject: Getting download sizes right: proof of concept
Date: Wed, 26 Feb 2020 02:18:47 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

I'd need someone to take this sketch and integrate it into the build
system (I just don't really understand the build system).

It is shown how to place a request for file size into
Documentation/web.texi and there is a script that will convert such
requests found in HTML files into user-readable size specifications.

It's HTML only (so no size specs in plain text or info or PDF) because I
don't quite see the point for other formats.  And in PDF, this kind of
after-the-fact substitution would be actually pretty hard to do.

Anybody want to see what it takes to get this across the finishing line?

-- 
David Kastrup
>From 2b318c869bb0f968b25c6287cb46e5d63c1cf7b5 Mon Sep 17 00:00:00 2001
From: David Kastrup <address@hidden>
Date: Wed, 26 Feb 2020 02:07:27 +0100
Subject: [PATCH] Get download sizes show up correctly

This calculates download sizes as the last step of HTML generation and
puts them into the HTML files for reference.

It does that by inserting appropriate HTML comments into the
respective files that refer to the files in question.

After the web page has been generated, it runs the
scripts/build/fix-docsize.sh script in the respective download
directories, specifying the HTML file names where such comments should
be searched and replaced on its command line.

This script uses ls -lh in order to get a human-readable size spec.
---
 Documentation/web.texi       | 16 ++++++++++++++--
 scripts/build/fix-docsize.sh | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 2 deletions(-)
 create mode 100755 scripts/build/fix-docsize.sh

diff --git a/Documentation/web.texi b/Documentation/web.texi
index 9d91dd402b..2f78f9793f 100644
--- a/Documentation/web.texi
+++ b/Documentation/web.texi
@@ -322,11 +322,23 @@ Distributions will want to install lilypond.info in 
postinstall, doing:
 
 @item @docLinkBig{\name\,\base\,\big\} @minus{}
   read this manual as one huge HTML page.
-  @*@ @ @emph{(large single download, \bigsize\)}
+  @*@ @
+  @ifnothtml
+  @emph{(large single download)}
+  @end ifnothtml
+@html
+<em>(large single download<!-- get-file-size: \base\-big-page.html -->)</em>
+@end html
 
 @item @docLinkPdf{\name\,\base\,\pdf\} @minus{}
   download as a PDF file.
-  @*@ @ @emph{(large single download, \pdfsize\)}
+  @*@ @
+  @ifnothtml
+  @emph{(large single download)}
+  @end ifnothtml
+@html
+<em>(large single download<!-- get-file-size: \base\.pdf -->)</em>
+@end html
 
 @end itemize
 
diff --git a/scripts/build/fix-docsize.sh b/scripts/build/fix-docsize.sh
new file mode 100755
index 0000000000..c03567f55b
--- /dev/null
+++ b/scripts/build/fix-docsize.sh
@@ -0,0 +1,32 @@
+#/bin/sh
+
+# Call with a number of HTML files as argument that may contain
+# comments of the form
+#
+# <!-- get-file-size: dir/filename.ext -->
+#
+# Those are going to be replaced by a comma and space followed by a
+# human-readable size indicating the size of the file for download.
+
+for source
+do
+    # Only treat files actually having file-size source comments
+    if fgrep -q '<!-- get-file-size:' "$source"
+    then
+       # We build an sed command having one replacement for each
+       # unique referenced file in a get-file-size comment.  The
+       # replacement takes the fifth argument of an ls -lh command, a
+       # posix way of getting a human-readable file size.  Since the
+       # command has to be assembled before sed -i even gets called,
+       # we can even reference the file itself in this manner,
+       # getting its size before the replacement of course.
+       sed -i \
+           "$(sed -n '/<!-- get-file-size: /s/^.*<!-- get-file-size: *\([^ 
]*\) .*$/\1/p'  "$source"|
+                 sort -u |
+                 while read filename
+                 do
+                     [ -r "$filename" ] && echo "s|<!-- get-file-size: 
$filename -->|, \
+$(ls -lh "$filename"|(read a b c d e f;echo $e))|"
+                 done)" "$source"
+    fi
+done
-- 
2.20.1


reply via email to

[Prev in Thread] Current Thread [Next in Thread]