meso-web

Sources of the |Méso|Star> website
git clone git://git.meso-star.fr/meso-web.git
Log | Files | Refs | README | LICENSE

commit 0c2d8d2fefb113e61d47a0c4e8d7c27131e2adfb
parent 35a8028a9c41ae8429e6c50bd9c0b735a3ea2e6f
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 25 Aug 2025 14:39:32 +0200

Make the print_downloads shell function generic

So that it can be reused in sections other than Solstice

Diffstat:
Mmeso-web.sh | 111+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msolstice/solstice-downloads.sh | 101++-----------------------------------------------------------------------------
2 files changed, 113 insertions(+), 99 deletions(-)

diff --git a/meso-web.sh b/meso-web.sh @@ -36,3 +36,114 @@ sections() | cut -d' ' -f2 \ | sed -e 's/[[:space:]]/\\ /g' } + +# Inline the HTML formatting of a table listing archive to download +print_downloads() # section, archive_prefix, OS ... +( + _section="$1" + _prefix="$2" + + shift 2 + + for _i in "$@"; do + case "${_i}" in + [Ll]inux) _os_linux="1" ;; + [Ww]indows) _os_windows="1" ;; + *) ;; # Unsuported OS + esac + done + + cd -- "${_section}" || exit 1 + + # Table header + echo '<table class="list">' + echo ' <tr>' + echo ' <th>Version</th>' + if [ -n "${_os_linux}" ]; then + echo ' <th>GNU/Linux 64-bits</th>' + fi + if [ -n "${_os_windows}" ]; then + echo ' <th>Windows 64-bits</th>' + fi + echo ' <th>Sources</th>' + echo ' </tr>' + + # Define the basic regular expression of a version number + _version_re="[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}" + _version_re="${_version_re}\(-r[0-9]\{1,\}\)\{0,1\}" + + # Browse all tarball files in the "downloads" subdirectory. Sort them + # in descending order according to lexicographical order. This may + # result in an incorrect order with regard to the version number. For + # example, version 9 will be considered higher than version 10. Some + # implementations offer an option to process version strings + # naturally, but this is not POSIX-compliant. So let's leave it as is, + # as there are currently no sorting issues. + find downloads -name "${_prefix}-*.tar.gz" \ + | grep -e "${_prefix}-${_version_re}-[^\(Sources\)].\{0,\}\.tar\.gz" \ + | sort -r \ + | while read -r _arch; do + + # Extract the version from + _version=$(echo "${_arch}" \ + | sed "s/downloads\/${_prefix}-\(${_version_re}\).\{0,\}$/\1/g") + + # Setup archive names + _linux="${_arch}" + _windows="downloads/${_prefix}-${_version}-Win64.zip" + _source1="downloads/${_prefix}-${_version}-Sources.zip" + _source2="downloads/${_prefix}-${_version}-Source.zip" + _source3="downloads/${_prefix}-${_version}-Sources.tar.gz" + _source4="downloads/${_prefix}-${_version}-Source.tar.gz" + + # Define the list to be referenced in each cell of the current + # version: first the GNU/Linux archive, then the Windows archive, + # and finally the corresponding sources. Since sources can have + # multiple names, find the one that matches the archive version, + # otherwise use a default name. The existence of the various + # archives available for download is verified below. The purpose + # here is simply a matter of providing three file names that could + # fill the cells in the row. + _dl="" + if [ -n "${_os_linux}" ]; then _dl="${_dl} ${_linux}"; fi + if [ -n "${_os_windows}" ]; then _dl="${_dl} ${_windows}"; fi + if [ -f "${_source1}" ]; then _dl="${_dl} ${_source1}"; + elif [ -f "${_source2}" ]; then _dl="${_dl} ${_source2}"; + elif [ -f "${_source3}" ]; then _dl="${_dl} ${_source3}"; + else _dl="${_dl} ${_source4}"; fi + + printf ' <tr>\n' # Let's get started on filling the line + + # Print the version in the first cell of the row + printf ' <td>%s</td>\n' "${_version}" + + # Iterate over the 3 filenames previously define and provide a link + # to it if their exist onto disk. For instance, a GNU/Linux archive + # can be provided while a Windows version is missing. + for _i in ${_dl}; do + + printf ' <td>\n' + + if [ -f "${_i}" ]; then + # The archive exists. Display a link to it whose label depends + # on the archive type (tarball or zip) + printf ' [<a href="%s">' "${_i}" + [ "${_i#*tar.gz}" != "${_i}" ] && printf 'tarball' || printf 'zip' + printf '</a>]\n' + fi + + # Display a link to the archive signature, if it exists + if [ -f "${_i}.sig" ]; then + printf ' [<a href="%s.sig">pgp</a>]\n' "${_i}" + fi + printf ' </td>\n' + done + + printf ' </tr>\n' # That's all for this row + done + + # The table is complete. Don't forget to add a line break after it to + # signal to Markdown that the embedded HTML code has ended. + printf '</table>\n' + printf '\n' +) diff --git a/solstice/solstice-downloads.sh b/solstice/solstice-downloads.sh @@ -16,112 +16,15 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. . "./config.sh.in" +. "../meso-web.sh" set -e -######################################################################## -# Helper function -######################################################################## -# Inline the HTML formatting of a table listing Solstice archive to -# download -print_downloads() -{ - # Table header - echo '<table class="list">' - echo ' <tr>' - echo ' <th>Version</th>' - echo ' <th>GNU/Linux 64-bits</th>' - echo ' <th>Windows 64-bits</th>' - echo ' <th>Sources</th>' - echo ' </tr>' - - # Define the basic regular expression of a version number - _version_re="[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}" - _version_re="${_version_re}\(-r[0-9]\{1,\}\)\{0,1\}" - - # Browse all tarball files in the "downloads" subdirectory. Sort them - # in descending order according to lexicographical order. This may - # result in an incorrect order with regard to the version number. For - # example, version 9 will be considered higher than version 10. Some - # implementations offer an option to process version strings - # naturally, but this is not POSIX-compliant. So let's leave it as is, - # as there are currently no sorting issues. - find downloads -name "Solstice*.tar.gz" \ - | grep -e "Solstice-${_version_re}-[^\(Sources\)].\{0,\}\.tar\.gz" \ - | sort -r \ - | while read -r _arch; do - - # Extract the version from - _version=$(echo "${_arch}" \ - | sed "s/downloads\/Solstice-\(${_version_re}\).\{0,\}$/\1/g") - - # Setup archive names - _linux="${_arch}" - _windows="downloads/Solstice-${_version}-Win64.zip" - _source1="downloads/Solstice-${_version}-Sources.zip" - _source2="downloads/Solstice-${_version}-Source.zip" - _source3="downloads/Solstice-${_version}-Sources.tar.gz" - _source4="downloads/Solstice-${_version}-Source.tar.gz" - - # Define the list to be referenced in each cell of the current - # version: first the GNU/Linux archive, then the Windows archive, - # and finally the corresponding sources. Since sources can have - # multiple names, find the one that matches the archive version, - # otherwise use a default name. The existence of the various - # archives available for download is verified below. The purpose - # here is simply a matter of providing three file names that could - # fill the cells in the row. - _dl="${_linux}" - _dl="${_dl} ${_windows}"; - if [ -f "${_source1}" ]; then _dl="${_dl} ${_source1}"; - elif [ -f "${_source2}" ]; then _dl="${_dl} ${_source2}"; - elif [ -f "${_source3}" ]; then _dl="${_dl} ${_source3}"; - else _dl="${_dl} ${_source4}"; fi - - printf ' <tr>\n' # Let's get started on filling the line - - # Print the version in the first cell of the row - printf ' <td>%s</td>\n' "${_version}" - - # Iterate over the 3 filenames previously define and provide a link - # to it if their exist onto disk. For instance, a GNU/Linux archive - # can be provided while a Windows version is missing. - for _i in ${_dl}; do - - printf ' <td>\n' - - if [ -f "${_i}" ]; then - # The archive exists. Display a link to it whose label depends - # on the archive type (tarball or zip) - printf ' [<a href="%s">' "${_i}" - [ "${_i#*tar.gz}" != "${_i}" ] && printf 'tarball' || printf 'zip' - printf '</a>]\n' - fi - - # Display a link to the archive signature, if it exists - if [ -f "${_i}.sig" ]; then - printf ' [<a href="%s.sig">pgp</a>]\n' "${_i}" - fi - printf ' </td>\n' - done - - printf ' </tr>\n' # That's all for this row - done - - # The table is complete. Don't forget to add a line break after it to - # signal to Markdown that the embedded HTML code has ended. - printf '</table>\n' - printf '\n' -} - -######################################################################## -# Generate page content using Markdown formatting -######################################################################## # Title echo '# Downloads' # List of archives to download -print_downloads +print_downloads "${PWD%%/*}" Solstice Linux Windows # Release notes sed -n '/^## Release notes/,/^## License/p' "${readme}" | sed '$d'