[PATCH 0/2] docs: Simplify build of HTML files and fix 'edit' links for NEWS and hvsupport

Peter Krempa (2): docs: meson: Simplify generation of html files docs: build: Use proper path to file in 'contribute' link docs/meson.build | 46 +++++++++++---------------------------- docs/page.xsl | 14 +++++++----- scripts/meson-html-gen.py | 2 +- 3 files changed, 22 insertions(+), 40 deletions(-) -- 2.26.2

Just convert 'docs_html_in_files' into 'docs_html_in_gen'. The target definitions for those were almost the same. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- docs/meson.build | 47 ++++++++++++++--------------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/docs/meson.build b/docs/meson.build index 2f06e8eace..e81251f29d 100644 --- a/docs/meson.build +++ b/docs/meson.build @@ -192,49 +192,29 @@ docs_rst2html_gen = generator( capture: true, ) -foreach name : docs_html_in_files - html_in_file = '@0@.html.in'.format(name) - html_file = '@0@.html'.format(name) - - out_file = custom_target( - html_file, - input: html_in_file, - output: html_file, - command: [ - meson_python_prog, - python3_prog.path(), - meson_html_gen_prog.path(), - xsltproc_prog.path(), - xmllint_prog.path(), - meson.build_root(), - docs_timestamp, - site_xsl, - '@INPUT@', - '@OUTPUT@', - html_in_file, - ], - depends: [ aclperms_gen ], - depend_files: [ page_xsl ], - install: true, - install_dir: docs_html_dir, - ) - - install_web_deps += out_file - install_web_files += '@0@:@1@'.format(out_file.full_path(), docs_html_dir) -endforeach - # docs_html_in_gen: # each entry is a dictionary with following items: # name - base file name (required) # file - generated file (required) +# source - source filename (required) docs_html_in_gen = [] +foreach name : docs_html_in_files + html_in_file = '@0@.html.in'.format(name) + docs_html_in_gen += { + 'name': name, + 'file': html_in_file, + 'source': html_in_file, + } +endforeach + foreach name : docs_rst_files rst_file = '@0@.rst'.format(name) docs_html_in_gen += { 'name': name, 'file': docs_rst2html_gen.process(rst_file), + 'source': rst_file, } endforeach @@ -262,17 +242,18 @@ hvsupport_html_in = custom_target( docs_html_in_gen += { 'name': 'hvsupport', 'file': hvsupport_html_in, + 'source': 'hvsupport.html.in', } news_html_in = docs_rst2html_gen.process(meson.source_root() / 'NEWS.rst') docs_html_in_gen += { 'name': 'news', 'file': news_html_in, + 'source': 'NEWS.rst', } foreach data : docs_html_in_gen html_file = '@0@.html'.format(data['name']) - rst_in_file = '@0@.rst'.format(data['name']) out_file = custom_target( html_file, @@ -289,7 +270,7 @@ foreach data : docs_html_in_gen site_xsl, '@INPUT@', '@OUTPUT@', - rst_in_file, + data['source'], ], depends: [ aclperms_gen ], depend_files: [ page_xsl ], -- 2.26.2

NEWS.xsl is based in the root of the repository and 'hvsupport.html' doesn't have a backing file which can be edited since it's fully generated. Our 'contribute -> edit this page' link on the bottom of the page is wrong in those cases. Fix it by adding the contribute section only when there's a source and base the 'source' of a html file in the root of the repository. Along with that we need to modify the scripts/meson-html-gen.py script to accept optional 'pagesrc' and the XSL template to skip the 'contribute' section when we don't have a source. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- docs/meson.build | 9 ++++----- docs/page.xsl | 14 ++++++++------ scripts/meson-html-gen.py | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/docs/meson.build b/docs/meson.build index e81251f29d..aaa3040598 100644 --- a/docs/meson.build +++ b/docs/meson.build @@ -197,7 +197,7 @@ docs_rst2html_gen = generator( # each entry is a dictionary with following items: # name - base file name (required) # file - generated file (required) -# source - source filename (required) +# source - source filename relative to repository root (optional, if there is no source) docs_html_in_gen = [] foreach name : docs_html_in_files @@ -205,7 +205,7 @@ foreach name : docs_html_in_files docs_html_in_gen += { 'name': name, 'file': html_in_file, - 'source': html_in_file, + 'source': 'docs' / html_in_file, } endforeach @@ -214,7 +214,7 @@ foreach name : docs_rst_files docs_html_in_gen += { 'name': name, 'file': docs_rst2html_gen.process(rst_file), - 'source': rst_file, + 'source': 'docs' / rst_file, } endforeach @@ -242,7 +242,6 @@ hvsupport_html_in = custom_target( docs_html_in_gen += { 'name': 'hvsupport', 'file': hvsupport_html_in, - 'source': 'hvsupport.html.in', } news_html_in = docs_rst2html_gen.process(meson.source_root() / 'NEWS.rst') @@ -270,7 +269,7 @@ foreach data : docs_html_in_gen site_xsl, '@INPUT@', '@OUTPUT@', - data['source'], + data.get('source', []), ], depends: [ aclperms_gen ], depend_files: [ page_xsl ], diff --git a/docs/page.xsl b/docs/page.xsl index 6923871400..bdd57ba2e0 100644 --- a/docs/page.xsl +++ b/docs/page.xsl @@ -166,12 +166,14 @@ <li><a href="http://serverfault.com/questions/tagged/libvirt">serverfault</a></li> </ul> </div> - <div id="contribute"> - <h3>Contribute</h3> - <ul> - <li><a href="https://gitlab.com/libvirt/libvirt/-/blob/master/docs/{$pagesrc}">edit this page</a></li> - </ul> - </div> + <xsl:if test="$pagesrc != ''"> + <div id="contribute"> + <h3>Contribute</h3> + <ul> + <li><a href="https://gitlab.com/libvirt/libvirt/-/blob/master/{$pagesrc}">edit this page</a></li> + </ul> + </div> + </xsl:if> <div id="conduct"> Participants in the libvirt project agree to abide by <a href="{$href_base}governance.html#codeofconduct">the project code of conduct</a> </div> diff --git a/scripts/meson-html-gen.py b/scripts/meson-html-gen.py index 08041f14ec..dbf238de54 100755 --- a/scripts/meson-html-gen.py +++ b/scripts/meson-html-gen.py @@ -12,7 +12,7 @@ parser.add_argument("timestamp", type=str, help="docs timestamp") parser.add_argument("style", type=str, help="XSL stile file") parser.add_argument("infile", type=str, help="path to source HTML file") parser.add_argument("htmlfile", type=str, help="path to generated HTML file") -parser.add_argument("pagesrc", type=str, help="path to source file used for edit this page") +parser.add_argument("pagesrc", type=str, default="", nargs='?', help="(optional) path to source file used for edit this page") args = parser.parse_args() name = os.path.basename(args.htmlfile).replace('.html', '') -- 2.26.2

On a Monday in 2020, Peter Krempa wrote:
Peter Krempa (2): docs: meson: Simplify generation of html files docs: build: Use proper path to file in 'contribute' link
docs/meson.build | 46 +++++++++++---------------------------- docs/page.xsl | 14 +++++++----- scripts/meson-html-gen.py | 2 +- 3 files changed, 22 insertions(+), 40 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (3)
-
Andrea Bolognani
-
Ján Tomko
-
Peter Krempa