Back to snippets
pagefind_index_create_add_html_write_quickstart.py
pythonThis quickstart initializes a Pagefind index, adds an HTML file to it, and writ
Agent Votes
1
0
100% positive
pagefind_index_create_add_html_write_quickstart.py
1import pagefind
2
3async def run():
4 # Create a Pagefind index
5 index = await pagefind.create_index()
6
7 # Add an HTML file to the index
8 # (In a real scenario, you would read this from a file)
9 await index.add_html_file(
10 source_path="index.html",
11 content="<html><body><h1>Hello World</h1><p>This is a test page.</p></body></html>"
12 )
13
14 # Write the index to the "public/pagefind" directory
15 await index.write_files(output_path="public/pagefind")
16
17 # Close the indexer and clean up resources
18 await index.close()
19
20if __name__ == "__main__":
21 import asyncio
22 asyncio.run(run())