-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(scripts): added the wordcount script
This script gets statistics for the book.
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# wordcount | ||
# | ||
# Given a set of markdown files, counts the words, approximates | ||
# the pages and summarises. Outputs in CSV. | ||
# | ||
# Example: | ||
# ./scripts/wordcount.sh ./website/content/docs/section*/**/_index.md > statistics.csv | ||
|
||
# Write out the CSV column titles. | ||
echo -e '"Path","Section","Title","Wordcount","Pagecount"' | ||
|
||
# Go through each file we'll get statistics for. | ||
for file in $@; do | ||
# Get the section from the folder structure - perhaps better to put it in | ||
# the frontmatter in the future? | ||
section=$(basename $(dirname $(dirname "$file"))) | ||
|
||
# Rip out the title from the frontmatter. | ||
title=$(cat $file |\ | ||
grep 'title: ' |\ | ||
sed -E 's/.*title:[[:space:]]*["]?([^"]*)["]?$/\1/') | ||
|
||
# Get the wordcount. | ||
wc=$(wc -w < "$file" | tr -d ' ') | ||
|
||
# Get the pagecount. | ||
pc=$(( (wc/500) + 1 )) | ||
|
||
# Write the results as a line of CSV. | ||
echo -e "\"$file\",\"$section\",\"$title\",\"$wc\",\"$pc\"" | ||
|
||
done |