This commit is contained in:
8
search-index-json.py
Normal file → Executable file
8
search-index-json.py
Normal file → Executable file
@@ -2,6 +2,8 @@ import os
|
||||
import json
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
OUTPUT_DIR = os.path.normpath(os.environ.get("SITE_OUTPUT_DIR", "output"))
|
||||
|
||||
def strip_html_tags(html):
|
||||
soup = BeautifulSoup(html, "html.parser")
|
||||
for tag in soup(["script", "style"]):
|
||||
@@ -25,7 +27,7 @@ def create_folder_structure_json(path):
|
||||
for entry in os.listdir(path):
|
||||
|
||||
entry_path = os.path.join(path, entry)
|
||||
base_url = entry_path[6:]
|
||||
base_url = os.path.relpath(entry_path, OUTPUT_DIR)
|
||||
if os.path.isdir(entry_path):
|
||||
result['children'].append(
|
||||
create_folder_structure_json(entry_path)
|
||||
@@ -52,10 +54,10 @@ def create_folder_structure_json(path):
|
||||
return result
|
||||
|
||||
|
||||
folder_path = 'output/'
|
||||
folder_path = OUTPUT_DIR
|
||||
folder_json = create_folder_structure_json(folder_path)
|
||||
|
||||
output_file = 'output/test.json'
|
||||
output_file = os.path.join(OUTPUT_DIR, 'test.json')
|
||||
with open(output_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(folder_json, f, indent=4, ensure_ascii=False)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user