mirror of
https://github.com/YunoHost/doc.git
synced 2024-09-03 20:06:26 +02:00
Attempt to add travis tests (+ autolinter script for links)
This commit is contained in:
parent
e41e91b37f
commit
2ea08ef1e3
4 changed files with 62 additions and 0 deletions
5
.travis.yml
Normal file
5
.travis.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
language: bash
|
||||||
|
|
||||||
|
script:
|
||||||
|
- bash tests/dead_links.sh
|
||||||
|
- bash tests/unreferenced_pages.sh
|
19
tests/dead_links.sh
Normal file
19
tests/dead_links.sh
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
returncode=0
|
||||||
|
|
||||||
|
# Find all markdown links and generate a list of filename.md:N:linktarget (with N the line number)
|
||||||
|
for LINK in $(grep -nr -o -E "\]\(\/?(\w|-)+\)" ./*.md | tr -d ']()/')
|
||||||
|
do
|
||||||
|
PAGE=$(echo $LINK | awk -F: '{print $3}')
|
||||||
|
[ -e "$PAGE.md" ] || echo "This link looks dead (page doesn't exist in english?) $LINK"
|
||||||
|
[ -e "$PAGE.md" ] || returncode=1
|
||||||
|
done
|
||||||
|
|
||||||
|
# Find all HTML/href links and generate a list of filename.md:N:linktarget (with N the line number)
|
||||||
|
for LINK in $(grep -nr -o -E 'href="\/?(\w|-)+\"' ./*.md | sed -E 's@href="/?@@g' | tr -d '"')
|
||||||
|
do
|
||||||
|
PAGE=$(echo $LINK | awk -F: '{print $3}')
|
||||||
|
[ -e "$PAGE.md" ] || echo "This link looks dead (page doesn't exist in english?) $LINK"
|
||||||
|
[ -e "$PAGE.md" ] || returncode=1
|
||||||
|
done
|
||||||
|
|
||||||
|
exit $returncode
|
13
tests/uniformize_links.sh
Normal file
13
tests/uniformize_links.sh
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
for FILE in $(ls *.md);
|
||||||
|
do
|
||||||
|
# Replace markdown links with full url ... we only need the relative url
|
||||||
|
sed -i -E 's@\(https://yunohost.org/#/(\w+)\)@(/\1)@g' $FILE
|
||||||
|
|
||||||
|
# Replace (/foo_fr) to (foo)
|
||||||
|
sed -i -E 's@\(\/?((\w|-)+)_(en|fr|es|it|ar|de|oc)\)@(/\1)@g' $FILE
|
||||||
|
|
||||||
|
# Replace href="/foo_fr" to href="foo"
|
||||||
|
sed -i -E 's@href="/?((\w|-)+)_(en|fr|es|it|ar|de|oc)"@href="/\1"@g' $FILE;
|
||||||
|
done
|
||||||
|
|
||||||
|
git checkout project_organization.md project_organization_fr.md
|
25
tests/unreferenced_pages.sh
Normal file
25
tests/unreferenced_pages.sh
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
|
||||||
|
|
||||||
|
MARKDOWN_TARGETS=$(grep -nr -o -E "\]\(\/?(\w|-)+\)" ./*.md | tr -d ']()/' | awk -F: '{print $3}' | sort | uniq)
|
||||||
|
HTML_TARGETS=$(grep -nr -o -E 'href="\/?(\w|-)+\"' ./*.md | sed -E 's@href="/?@@g' | tr -d '"' | awk -F: '{print $3}' | sort | uniq)
|
||||||
|
|
||||||
|
ALL_TARGETS=$(echo $MARKDOWN_TARGETS $HTML_TARGETS)
|
||||||
|
|
||||||
|
PAGES=$(ls *.md | sed -E 's/(_(fr|it|de|ar|oc|es|ru))?.md//g' | sort | uniq)
|
||||||
|
|
||||||
|
returncode=0
|
||||||
|
|
||||||
|
for PAGE in $PAGES
|
||||||
|
do
|
||||||
|
if [[ $PAGE == "index" ]] || [[ $PAGE == "README" ]] || [[ $PAGE == "default" ]]
|
||||||
|
then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if ! echo $ALL_TARGETS | grep -q $PAGE
|
||||||
|
then
|
||||||
|
returncode=1
|
||||||
|
echo "The following page is not referenced by any other page :( -> $PAGE"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
exit $returncode
|
Loading…
Reference in a new issue