in kotlin-website.py [0:0]
def validate_links_weak(page, page_path):
for link in page.parsed_html.select('a'):
if 'href' not in link.attrs:
continue
href = urlparse(urljoin('/' + page_path, link['href']))
if href.scheme != '':
continue
endpoint, params = url_adapter.match(href.path, 'GET', query_args={})
if endpoint != 'page' and endpoint != 'get_index_page':
response = app.test_client().get(href.path)
if response.status_code == 404:
build_errors.append("Broken link: " + str(href.path) + " on page " + page_path)
continue
referenced_page = pages.get(params['page_path'])
if referenced_page is None:
build_errors.append("Broken link: " + str(href.path) + " on page " + page_path)
continue
if href.fragment == '':
continue
ids = []
for x in referenced_page.parsed_html.select('h1,h2,h3,h4'):
try:
ids.append(x['id'])
except KeyError:
pass
for x in referenced_page.parsed_html.select('a'):
try:
ids.append(x['name'])
except KeyError:
pass
if href.fragment not in ids:
build_errors.append("Bad anchor: " + str(href.fragment) + " on page " + page_path)
if not build_mode and len(build_errors) > 0:
errors_copy = []
for item in build_errors:
errors_copy.append(item)
build_errors.clear()
raise Exception("Validation errors " + str(len(errors_copy)) + ":\n\n" +
"\n".join(str(item) for item in errors_copy))