diff options
author | Bastien Nocera <hadess@hadess.net> | 2019-10-23 12:57:03 +0200 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2019-10-23 13:48:28 +0200 |
commit | d6dde0e65abe49f44c8c0f9b933c3df583900395 (patch) | |
tree | f9c2618de53ef4d2eeaf3a29734959150ffe3bb9 /web-export | |
parent | 75d6dee9f02660ba5f130a7c20b76b909a136c4f (diff) |
web-export: Generate an index.md file
Diffstat (limited to 'web-export')
-rw-r--r-- | web-export/index.md.in | 8 | ||||
-rwxr-xr-x | web-export/update.py | 31 |
2 files changed, 37 insertions, 2 deletions
diff --git a/web-export/index.md.in b/web-export/index.md.in new file mode 100644 index 0000000..60ccc0b --- /dev/null +++ b/web-export/index.md.in @@ -0,0 +1,8 @@ +% Freedesktop.org Specifications +% Bastien Nocera +% 2019 + + + +# Freedesktop.org Specifications + diff --git a/web-export/update.py b/web-export/update.py index eaba1f4..1c092fa 100755 --- a/web-export/update.py +++ b/web-export/update.py @@ -98,6 +98,13 @@ def get_main_branch(url): m = re.search('refs/heads/(.+)\t', out.decode('utf-8')) return m.group(1) +def open_file_with_template(dst, template): + fd = open(dst, 'w') + with open(template, 'r') as content_file: + content = content_file.read() + fd.write(content) + return fd + class VcsObject: def __init__(self, vcs, repo, file, revision = None): self.vcs = vcs @@ -223,7 +230,7 @@ class SpecObject(): raise Exception('Cannot convert \'%s\' to multiple-chunks HTML.\nThe command was %s' % (path, multiple_chunks_command)) self.multiple_chunks = True - def latestize(self): + def latestize(self, fd): filename_latest = '%s-latest%s' % (self.basename_no_ext, self.ext) path_latest = os.path.join(self.spec_dir, filename_latest) @@ -231,7 +238,11 @@ class SpecObject(): os.unlink(path_latest) os.symlink(self.filename, path_latest) + fd.write('\n- %s\n' % self.spec_dir) + if self.ext in ['.xml', '.sgml']: + fd.write(' - **version %s (' % self.version) + # One-chunk HTML html_path_latest = os.path.join(self.spec_dir, '%s-latest%s' % (self.basename_no_ext, '.html')) if os.path.exists(html_path_latest): @@ -240,8 +251,11 @@ class SpecObject(): (filename_no_ext, ext) = os.path.splitext(self.filename) html_filename = '%s%s' % (filename_no_ext, '.html') html_path = os.path.join(self.spec_dir, html_filename) + has_html_path = False if os.path.exists(html_path): os.symlink(html_filename, html_path_latest) + has_html_path = True + fd.write('[one page](%s)' % html_path_latest) # Multiple chunks html_dir_latest = os.path.join(self.spec_dir, 'latest') @@ -251,7 +265,15 @@ class SpecObject(): html_dir = os.path.join(self.spec_dir, self.version) if os.path.exists(html_dir): os.symlink(self.version, html_dir_latest) + if has_html_path: + fd.write(', ') + fd.write('[split pages](%s))**\n' % html_dir_latest) + else: + fd.write(')**\n') + return + + fd.write(' - **version %s ([%s format](%s))**\n' % (self.version, self.ext, path_latest)) SCRIPT = VcsObject('git', 'xdg/xdg-specs', 'web-export/update.py') SPECS_INDEX = VcsObject('git', 'xdg/xdg-specs', 'web-export/specs.idx') @@ -282,6 +304,7 @@ safe_mkdir(public_dir) latests = [] source_dirs = {} +index_fd = open_file_with_template(os.path.join(public_dir, 'index.md'), 'index.md.in') for line in lines: line = line.strip() @@ -306,7 +329,9 @@ for line in lines: # Create latest links if it's the first time we see this spec if (spec.spec_dir, spec.basename_no_ext) not in latests: latests.append((spec.spec_dir, spec.basename_no_ext)) - spec.latestize() + spec.latestize(index_fd) + else: + index_fd.write(' - [version %s](%s)\n' % (version, spec.spec_dir)) target_dir = os.path.join(public_dir, spec.spec_dir) src_dir = spec.spec_dir @@ -315,6 +340,8 @@ for line in lines: if src_dir not in source_dirs: source_dirs[src_dir] = target_dir +index_fd.close() + for dirs in source_dirs.items(): shutil.copytree(dirs[0], dirs[1], symlinks=True) |