Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/automate tags #182

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ cache: bundler

before_install:
- gem update --system
- gem install bundler jekyll
- gem install bundler
- gem install jekyll


before_script:
- chmod +x ./bin/setup
- ./bin/setup
- bundle exec jekyll build

script: bundle exec htmlproofer ./_site --only-4xx --allow-hash-href --assume-extension --check-opengraph --url-ignore "feed.xml,/facebook.com/"
script:
- ./tests/test_automatic_tags.sh
- bundle exec htmlproofer ./_site --only-4xx --allow-hash-href --assume-extension --check-opengraph --url-ignore "feed.xml,/facebook.com/"

env:
global:
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true # speeds up installation of html-proofer
- LC_ALL=en_US.UTF-8
- JEKYLL_ENV=production

31 changes: 31 additions & 0 deletions bin/tag_scraper
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

set -e

ACCEPTABLE_FILES=$(find _posts -type f -name "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-*" ! -name "*~" | xargs)

TAGS="$(grep -h tags: ${ACCEPTABLE_FILES} | sed -E 's/tags: \[(.*)\]/\1,/' | xargs | sed -E 's/ |,$//g' | sed -E 's/,/\n/g' | sort | uniq)"

if [ ! -d "_my_tags" ]
then
mkdir "_my_tags"
fi

for i in ${TAGS}; do
echo found tag: $i
if [ -e "_my_tags/${i}.md" ]
then
echo found _my_tags/${i}.md, not updating
else
echo creating _my_tags/${i}.md
firstletter=$(echo $i | cut -c1 | tr ‘[[:lower:]]’ ‘[[:upper:]]’)
otherletters=$(echo $i | cut -c2-)
capitalized="${firstletter}${otherletters}"
cat << EOF > "_my_tags/$i.md"
---
slug: $i
name: $capitalized
---
EOF
fi
done
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "chalk",
"scripts": {
"setup": "bin/setup",
"local": "bundle exec jekyll serve --drafts",
"publish": "bin/deploy"
"local": "bin/tag_scraper && bundle exec jekyll serve --drafts",
"publish": "bin/tag_scraper && bin/deploy"
},
"dependencies": {
"jquery": "^3.2.1",
Expand Down
171 changes: 171 additions & 0 deletions tests/test_automatic_tags.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
#!/usr/bin/env sh

set -e

# clean up target files
if test -d "./_site";then
rm -R _site/*
fi

if test -d "./_my_tags";then
rm -R _my_tags
fi

if test -e "./_posts/new_tags.md";then
rm _posts/new_tags.md
fi

if test -e "./_posts/2018-09-26-new_tags.md";then
rm _posts/2018-09-26-new_tags.md
fi


# populate _my_tags, and create directory
./bin/tag_scraper

if test ! -d "./_my_tags";then
echo "Failed to create _my_tags directory"
exit 1
fi

if test ! -e "./_my_tags/jekyll.md";then
echo "Failed to generate _my_tags/jekyll.md"
exit 1
fi

if test ! -e "./_my_tags/design.md";then
echo "Failed to generate _my_tags/design.md"
exit 1
fi

if test ! -e "./_my_tags/web.md";then
echo "Failed to generate _my_tags/web.md"
exit 1
fi

bundle exec jekyll build

if test ! -e "./_site/tag/web/index.html";then
echo "Failed to build tag pages in site"
exit 1
fi

if test ! -e "./_site/tags.html";then
echo "Failed to build tags.html tag cloud page in site"
exit 1
fi

echo "tags cloud, etc, built"

# now add a new post, and process it

cat <<EOF > "_posts/2018-09-26-new_tags.md"
---
layout: post
title: "Fake post with unique tags"
description: "The tag entries in _my_tags will be autogenerated."
tags: [automation, tags, tests]
---

This is a test post with some new tags.

EOF

./bin/tag_scraper

if test ! -e "./_my_tags/jekyll.md";then
echo "Failed to generate _my_tags/jekyll.md"
exit 1
fi

if test ! -e "./_my_tags/design.md";then
echo "Failed to generate _my_tags/design.md"
exit 1
fi

if test ! -e "./_my_tags/web.md";then
echo "Failed to generate _my_tags/web.md"
exit 1
fi

if test ! -e "./_my_tags/automation.md";then
echo "Failed to generate _my_tags/automation.md"
exit 1
fi

if test ! -e "./_my_tags/tags.md";then
echo "Failed to generate _my_tags/tags.md"
exit 1
fi

if test ! -e "./_my_tags/tests.md";then
echo "Failed to generate _my_tags/tests.md"
exit 1
fi

# build a second time
bundle exec jekyll build

echo "test new build of site"

if test ! -e "./_site/tag/tests/index.html"
then
echo "Failed to build new tag pages in site"
exit 1
else
echo "found tests index page"
fi

if test ! -e "./_site/posts/new-tags.html"
then
echo "Failed to add 2018-09-26-new-tags.md to site"
exit 1
else
echo "found posts/new-tags.html"
fi

for word in "automation" "design" "jekyll" "tags" "tests" "web"; do
if grep -q $word "./_site/tags.html"; ##note the space after the string you are searching for
then
echo "Hooray!! Found $word in tag cloud"
else
echo "Oops!! $word not found"
exit 1
fi
done

# should ignore files that don't fit the jekyll post pattern
cat <<EOF > "_posts/hidden_tags.md"
---
layout: post
title: "Another fake post with unique tags"
description: "The tag entries in _my_tags should not be autogenerated."
tags: [bananas, pancakes]
---

This is a test post with some new tags.

EOF

./bin/tag_scraper

# build a third time
bundle exec jekyll build


if test -e "./_site/posts/hidden-tags.html"
then
echo "Mistakenly added hidden-tags.html to site"
exit 1
fi

for word in "bananas" "pancakes"; do
if grep -q $word "./_site/tags.html"; ##note the space after the string you are searching for
then
echo "Oops!! $word was found, but should have been ignored"
exit 1
fi
done


echo "done"