[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
www/server/source/sitemap-generator sitemap-gen...
From: |
Ineiev |
Subject: |
www/server/source/sitemap-generator sitemap-gen... |
Date: |
Sun, 9 Apr 2023 02:31:48 -0400 (EDT) |
CVSROOT: /web/www
Module name: www
Changes by: Ineiev <ineiev> 23/04/09 02:31:48
Modified files:
server/source/sitemap-generator: sitemap-generator.py
Log message:
Add intruductory comments. Add script version.
Highlight untranslated optional templates in a distinct way.
CVSWeb URLs:
http://web.cvs.savannah.gnu.org/viewcvs/www/server/source/sitemap-generator/sitemap-generator.py?cvsroot=www&r1=1.15&r2=1.16
Patches:
Index: sitemap-generator.py
===================================================================
RCS file: /web/www/www/server/source/sitemap-generator/sitemap-generator.py,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- sitemap-generator.py 11 Aug 2015 16:00:41 -0000 1.15
+++ sitemap-generator.py 9 Apr 2023 06:31:47 -0000 1.16
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
#
-# Sitemap generator
-# Copyright © 2011-2012 WacÅaw Jacek
-# Copyright © 2014, 2015 Free Software Foundation, Inc.
+# Sitemap generator for www.gnu.org.
+#
+# Copyright © 2011, 2012 WacÅaw Jacek
+# Copyright © 2014, 2015, 2023 Free Software Foundation, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -17,11 +18,26 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# This script generates:
+#
+# * sitemap*.xml compliant with the Sitemap protocol [0];
+# * /server/sitemap.html for human visitors;
+# * gettext files with translated page titles for GNUN to update
+# the localized versions of /server/sitemap.html, see [1];
+# * sitemap.html.translist, a list of translations with SSI instructions
+# to select by language [2].
+#
+# [0] https://www.sitemaps.org/
+# [1] https://www.gnu.org/s/trans-coord/manual/gnun/html_node/Sitemap.html
+# [2] https://www.gnu.org/server/trans-map.html
+
import os
import re
import sys
import datetime
+VERSION = '0.16'
+
LANGCODE_REGEXP = '(?P<langcode>[a-z]{2}|[a-z]{2}-[a-z]{2})'
CHARSET_REGEXP_CONTENT_PART = 'content=\s*(?P<cquote>[\'"])text/html;\s*' \
+ 'charset\s*=\s*(?P<encoding>.*?)(?P=cquote)'
@@ -392,7 +408,7 @@
fd = open(OUTPUT_FILE_NAME + '.' + lang + '.po', 'w')
d = datetime.datetime.now()
fd.write(\
-'''# Automatically generated by sitemap-generator.py
+'''# Automatically generated by sitemap-generator.py ''' + VERSION + '''
msgid ""
msgstr ""
"Project-Id-Version: sitemap.html\\n"
@@ -425,23 +441,39 @@
return name
# Check how outdated the translation is; return the respective tag name.
-def get_outdated_tag (directory, base, lang):
- po = join_url_paths(directory, 'po')
- po = join_url_paths(po, base + '.' + lang +'.po')
- po = join_url_paths(TOP_DIRECTORY, po)
- if not os.path.exists(po):
- return 'del'
- path = join_url_paths(directory, base + '.' + lang + '.html')
- html = open(join_url_paths(TOP_DIRECTORY, path))
- try:
+def get_outdated_tags (directory, base, lang):
+ directory = join_url_paths (TOP_DIRECTORY, directory)
+ po = join_url_paths (directory, 'po', base + '.')
+ pot = po + '.pot'
+ po = po + lang +'.po'
+ if not os.path.isfile (po):
+ if not os.path.isfile (pot):
+ return ['del', 'i']
+ return ['del']
+ ret = []
+ path = join_url_paths (directory, base + '.' + lang + '.html')
+ html = open (path)
for line in html:
- if line.find('<!--#set var="OUTDATED_SINCE"') >= 0:
- html.close()
- return 'em'
- html.close()
- finally:
+ if line.find ('<title>') >= 0:
+ break
+ if line.find ('<!--#set var="OUTDATED_SINCE"') >= 0:
+ ret = ['i']
+ break
html.close()
- return ''
+ return ret
+
+def tag_sequence (tags, slash):
+ ret = ''
+ for tag in tags:
+ ret = ret + '<' + slash + tag + '>'
+ return ret
+
+def open_tags (tags):
+ return tag_sequence (tags, '')
+
+def close_tags (tags):
+ tags.reverse ()
+ return tag_sequence (tags, '/')
sitemap_urls = 0
sitemap_no = 0
@@ -517,12 +549,7 @@
if not lang in translation_linguas:
translation_linguas.append(lang)
languages.append('.' + lang)
- emph_open = ''
- emph_close = ''
- emph = get_outdated_tag (directory, base, lang)
- if emph != '':
- emph_open = '<' + emph + '>'
- emph_close = '</' + emph + '>'
+ emph = get_outdated_tags (directory, base, lang)
path = join_url_paths(directory, trans)
name = path
if trans in titles:
@@ -531,10 +558,10 @@
langs = langs + '|'
langs = langs + lang
item = item + '<!--#if expr="$qs = /,' + lang \
- + ',/" -->\n' + emph_open + '[' + lang + '] <a ' \
+ + ',/" -->\n' + open_tags (emph) + '[' + lang + '] <a ' \
+ 'hreflang="' + lang + '" lang="' + lang + '" xml:lang="' \
+ lang + '" href="/' + path + '">\n' + name + '</a>' \
- + emph_close + '<br /><!--#endif -->'
+ + close_tags (emph) + '<br /><!--#endif -->'
append_sitemap_org(directory, base, languages)
if len(langs) == 0:
return
@@ -717,16 +744,13 @@
-<!--
-
- This file is automatically generated by ''' + sys.argv[0] + '''.
-
- The generator is also in charge of partially updating
- the existing translations of this file. This is why you
- should neither edit this file manually, nor commit it alone
- without merging the updates to the translations.
+<!-- This file is automatically generated by ''' \
+ + sys.argv[0] + ' ' + VERSION + ' ' + '''.
- -->
+The generator is also in charge of partially updating
+the existing translations of this file. This is why you
+should neither edit this file manually, nor commit it alone
+without merging the updates to the translations. -->
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- www/server/source/sitemap-generator sitemap-gen...,
Ineiev <=