Skip to content

Commit

Permalink
Add script for checking titles
Browse files Browse the repository at this point in the history
  • Loading branch information
janetkuo committed Jan 10, 2017
1 parent 586656c commit d879046
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ install:
script:
- go test -v k8s.io/kubernetes.github.io/test
- $GOPATH/bin/md-check --root-dir=$HOME/gopath/src/k8s.io/kubernetes.github.io
- ./verify-entry-toc.sh
- ./verify-docs-format.sh
2 changes: 2 additions & 0 deletions skip_title_check.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Put files you want to skip "titles:" check here:
docs/sitemap.md
48 changes: 48 additions & 0 deletions verify-docs-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

no_entry=false
no_entry_counter=0
no_title=false
no_title_counter=0

# Verify all docs/.../*.md files
for file in `find docs -name "*.md" -type f`; do
# 1. TOC check:
# Check they are referenced in at least one of _data/*.yml files.
# Skip checking files in skip_toc_check.txt
if ! grep -q "${file}" skip_toc_check.txt; then
path=${file%.*}
# abc/index.md should point to abc, not abc/index
path=${path%%index}
if ! grep -q "${path}" _data/*.yml; then
echo "Error: ${file} doesn't have an entry in the table of contents under _data/*.yml"
no_entry=true
no_entry_counter=$[no_entry_counter+1]
fi
fi

# 2. Title check:
# Check they have a proper title.
# Skip checking files in skip_title_check.txt
# Title should start with "title:" and can have several spaces/tabs between
# non-space/tab content.
# For example, "title:", " title: abc", and "title:" aren't valid,
# but "title: abc", "title:def" and "title: def ghi" are both valid.
if ! grep -q "${file}" skip_title_check.txt; then
if ! grep -q "^title:\s*[^\s]" ${file}; then
echo "Error: ${file} doesn't have a proper title defined!"
no_title=true
no_title_counter=$[no_title_counter+1]
fi
fi
done

if ${no_entry}; then
echo "Found ${no_entry_counter} files without entries. For how to fix it, see http://kubernetes.io/docs/contribute/write-new-topic/#creating-an-entry-in-the-table-of-contents"
exit 1
fi

if ${no_title}; then
echo "Found ${no_title_counter} files without titles."
exit 1
fi
22 changes: 0 additions & 22 deletions verify-entry-toc.sh

This file was deleted.

0 comments on commit d879046

Please sign in to comment.