-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_sitemap.py
27 lines (23 loc) · 1.01 KB
/
generate_sitemap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from bs4 import BeautifulSoup as bs
import os
import sys
#pull in path information from Flare. Triggered by post-build event on the Target
outputDestination = sys.argv[1]
initialSitemap = os.path.join(outputDestination, 'sitemap.xml')
#Open and get out the xml content into a string
with open(initialSitemap, "r") as file:
sitemapContent = file.readlines()
sitemapContent = "".join(sitemapContent)
sitemap_bs_content = bs(sitemapContent, "html.parser")
#format the string into proper sitemap .html format
urls = [element.text for element in sitemap_bs_content.findAll('loc')]
urls.sort()
htmlElements = ["<ul style='list-style:none'>"]
for element in urls:
htmlElements.append("<li><a href=" + element + ">" + element.split('/')[-1] + "</a></li>")
htmlElements.append("</ul>")
htmlPage = '\r\n'.join(htmlElements)
#create and save the new file in the output
updatedSitemap = open(os.path.join(outputDestination, "searchkb.html"), 'w')
updatedSitemap.write(htmlPage)
updatedSitemap.close()