diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..ec7369c8 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: bash + +script: + - bash tests/dead_links.sh + - bash tests/unreferenced_pages.sh diff --git a/tests/dead_links.sh b/tests/dead_links.sh new file mode 100644 index 00000000..f51cec96 --- /dev/null +++ b/tests/dead_links.sh @@ -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 diff --git a/tests/uniformize_links.sh b/tests/uniformize_links.sh new file mode 100644 index 00000000..4a4e76be --- /dev/null +++ b/tests/uniformize_links.sh @@ -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 diff --git a/tests/unreferenced_pages.sh b/tests/unreferenced_pages.sh new file mode 100644 index 00000000..21c72119 --- /dev/null +++ b/tests/unreferenced_pages.sh @@ -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