@@ -76,11 +76,14 @@ print(list(suggestion.getResults(0, suggestion_count)))
7676### Write a ZIM file
7777
7878``` py
79+ import base64
80+ import pathlib
81+
7982from libzim.writer import Creator, Item, StringProvider, FileProvider, Hint
8083
8184
8285class MyItem (Item ):
83- def __init__ (self , title , path , content = " " , fpath = None ):
86+ def __init__ (self , title , path , content = " " , fpath = None ):
8487 super ().__init__ ()
8588 self .path = path
8689 self .title = title
@@ -108,14 +111,26 @@ class MyItem(Item):
108111content = """ <html><head><meta charset="UTF-8"><title>Web Page Title</title></head>
109112<body><h1>Welcome to this ZIM</h1><p>Kiwix</p></body></html>"""
110113
114+ pathlib.Path(" home-fr.html" ).write_text(
115+ """ <html><head><meta charset="UTF-8">
116+ <title>Bonjour</title></head>
117+ <body><h1>this is home-fr</h1></body></html>"""
118+ )
119+
111120item = MyItem(" Hello Kiwix" , " home" , content)
112121item2 = MyItem(" Bonjour Kiwix" , " home/fr" , None , " home-fr.html" )
113122
123+ # illustration = pathlib.Path("icon48x48.png").read_bytes()
124+ illustration = base64.b64decode(
125+ " iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAAGXRFWHRTb2Z0d2FyZQBB"
126+ " ZG9iZSBJbWFnZVJlYWR5ccllPAAAAANQTFRFR3BMgvrS0gAAAAF0Uk5TAEDm2GYAAAAN"
127+ " SURBVBjTY2AYBdQEAAFQAAGn4toWAAAAAElFTkSuQmCC"
128+ )
129+
114130with Creator(" test.zim" ).config_indexing(True , " eng" ) as creator:
115131 creator.set_mainpath(" home" )
116132 creator.add_item(item)
117133 creator.add_item(item2)
118- illustration = pathlib.Path(" icon48x48.png" ).read_bytes()
119134 creator.add_illustration(48 , illustration)
120135 for name, value in {
121136 " creator" : " python-libzim" ,
@@ -124,7 +139,7 @@ with Creator("test.zim").config_indexing(True, "eng") as creator:
124139 " publisher" : " You" ,
125140 " title" : " Test ZIM" ,
126141 " language" : " eng" ,
127- " date" : " 2024-06-30"
142+ " date" : " 2024-06-30" ,
128143 }.items():
129144
130145 creator.add_metadata(name.title(), value)
0 commit comments