1212Examples:
1313 $ python3 sites/generate/build_jekyll_md.py
1414"""
15+
16+ import argparse
1517import re
1618import gzip
1719import shutil
20+ import sys
21+ import tomllib
1822from pathlib import Path
1923from typing import Optional
2024
@@ -204,7 +208,15 @@ def convert(self):
204208 self .file_dst .write_text (md )
205209
206210
207- def build ():
211+ def build (standalone : bool ):
212+ """Build a jekyll project for documentation from original repo"""
213+ # Identify version
214+ with open ("../hurl/packages/hurl/Cargo.toml" , "rb" ) as f :
215+ data = tomllib .load (f )
216+ version = data ["package" ]["version" ]
217+ version = version .replace ("-SNAPSHOT" , "" )
218+ sys .stderr .write (f"version:{ version } \n " )
219+
208220 docs = [
209221 (
210222 Path ("../hurl/docs/home.md" ),
@@ -391,19 +403,23 @@ def build():
391403 FrontMatter (layout = "doc" , section = "Resources" ),
392404 False ,
393405 ),
394- (
395- Path ("../hurl/docs/standalone/hurl-5.0.1.md" ),
396- Path ("sites/hurl.dev/_docs/standalone/hurl-5.0.1.md" ),
397- FrontMatter (
398- layout = "standalone" ,
399- section = "Standalone" ,
400- title = "Hurl 5.0.1" ,
401- indexed = False ,
402- ),
403- False ,
404- ),
405406 ]
406407
408+ if standalone :
409+ docs .append (
410+ (
411+ Path (f"../hurl/docs/standalone/hurl-{ version } .md" ),
412+ Path (f"sites/hurl.dev/_docs/standalone/hurl-{ version } .md" ),
413+ FrontMatter (
414+ layout = "standalone" ,
415+ section = "Standalone" ,
416+ title = f"Hurl { version } " ,
417+ indexed = False ,
418+ ),
419+ False ,
420+ ),
421+ )
422+
407423 for src , dst , front_matter , force_list_numbering in docs :
408424 task = ConvertTask (
409425 file_src = src ,
@@ -453,21 +469,22 @@ def build():
453469 "../hurl/docs/assets/img/quiz-light.png" ,
454470 "sites/hurl.dev/assets/img/quiz-light.png" ,
455471 )
456- compress (src = Path ("../hurl/docs/standalone/hurl-5.0.1.md" ))
457- shutil .move (
458- "../hurl/docs/standalone/hurl-5.0.1.md.gz" ,
459- "sites/hurl.dev/assets/docs/hurl-5.0.1.md.gz" ,
460- )
461- compress (src = Path ("../hurl/docs/standalone/hurl-5.0.1.html" ))
462- shutil .move (
463- "../hurl/docs/standalone/hurl-5.0.1.html.gz" ,
464- "sites/hurl.dev/assets/docs/hurl-5.0.1.html.gz" ,
465- )
466- compress (src = Path ("../hurl/docs/standalone/hurl-5.0.1.pdf" ))
467- shutil .move (
468- "../hurl/docs/standalone/hurl-5.0.1.pdf.gz" ,
469- "sites/hurl.dev/assets/docs/hurl-5.0.1.pdf.gz" ,
470- )
472+ if standalone :
473+ compress (src = Path (f"../hurl/docs/standalone/hurl-{ version } .md" ))
474+ shutil .move (
475+ f"../hurl/docs/standalone/hurl-{ version } .md.gz" ,
476+ f"sites/hurl.dev/assets/docs/hurl-{ version } .md.gz" ,
477+ )
478+ compress (src = Path (f"../hurl/docs/standalone/hurl-{ version } .html" ))
479+ shutil .move (
480+ f"../hurl/docs/standalone/hurl-{ version } .html.gz" ,
481+ f"sites/hurl.dev/assets/docs/hurl-{ version } .html.gz" ,
482+ )
483+ compress (src = Path (f"../hurl/docs/standalone/hurl-{ version } .pdf" ))
484+ shutil .move (
485+ f"../hurl/docs/standalone/hurl-{ version } .pdf.gz" ,
486+ f"sites/hurl.dev/assets/docs/hurl-{ version } .pdf.gz" ,
487+ )
471488
472489
473490def compress (src : Path ):
@@ -476,9 +493,19 @@ def compress(src: Path):
476493 shutil .copyfileobj (f_in , f_out )
477494
478495
479- def main ():
480- build ()
496+ def main (standalone : bool ):
497+ build (standalone = standalone )
481498
482499
483500if __name__ == "__main__" :
484- main ()
501+ parser = argparse .ArgumentParser (
502+ description = "Build jekyll source from https://github.com/Orange-OpenSource/hurl"
503+ )
504+ parser .add_argument (
505+ "--standalone" ,
506+ action = "store_true" ,
507+ default = False ,
508+ help = "Generate standalone docs" ,
509+ )
510+ args = parser .parse_args ()
511+ main (standalone = args .standalone )
0 commit comments