Check dead or broken links
This commit is contained in:
4
Makefile
4
Makefile
@@ -47,6 +47,10 @@ server:
|
|||||||
build:
|
build:
|
||||||
@cd '$(PROJDIR)' && \
|
@cd '$(PROJDIR)' && \
|
||||||
lektor build --output-path ../bin --buildstate-path ../build-state -f ENABLE_APPCACHE
|
lektor build --output-path ../bin --buildstate-path ../build-state -f ENABLE_APPCACHE
|
||||||
|
@echo
|
||||||
|
@echo 'Checking dead links ...'
|
||||||
|
@python3 extras/find-dead-links.py
|
||||||
|
@echo
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
@echo
|
@echo
|
||||||
|
|||||||
32
extras/find-dead-links.py
Executable file
32
extras/find-dead-links.py
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
from contextlib import closing
|
||||||
|
from mmap import mmap, ACCESS_READ
|
||||||
|
|
||||||
|
rx_a = re.compile(br'[@(]\.\./([^/]*)')
|
||||||
|
|
||||||
|
|
||||||
|
def regex_file(file):
|
||||||
|
with open(file, 'r') as f:
|
||||||
|
with closing(mmap(f.fileno(), 0, access=ACCESS_READ)) as d:
|
||||||
|
for x in re.finditer(rx_a, d):
|
||||||
|
yield x.group(1).decode('utf-8')
|
||||||
|
|
||||||
|
|
||||||
|
base_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
dist_dir = os.path.join(base_dir, 'data', 'distribution')
|
||||||
|
all_ids = None
|
||||||
|
|
||||||
|
for path, dirs, files in os.walk(dist_dir):
|
||||||
|
if not all_ids:
|
||||||
|
all_ids = dirs
|
||||||
|
for lr_file in files:
|
||||||
|
if not lr_file.endswith('lr'):
|
||||||
|
continue
|
||||||
|
for link in regex_file(path + os.path.sep + lr_file):
|
||||||
|
if link not in all_ids:
|
||||||
|
short_name = os.path.basename(path) + os.path.sep + lr_file
|
||||||
|
print(f'dead-link: {short_name} ({link})')
|
||||||
|
|
||||||
|
print('done.')
|
||||||
Reference in New Issue
Block a user