Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 107 additions & 89 deletions front-matter-ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,111 +4,129 @@

# 'path' == '_posts' in 'documentation'
# 'path' == 'build/html' in 'py-docs'
# 'path' == 'r' in 'r-docs'
# 'path' == 'build' in 'r-docs'
try:
path = str(sys.argv[1])
except:
raise Exception("You need to specify a path that contains the files with front matter.")
raise Exception(
"You need to specify a path that contains the files with front matter."
)

def ci_check(checkList, error_message):
print("***********************************!")
print("Checking... {}".format(error_message))
if len(checkList) > 0:
print("NOT PASSED!\n")
print("List of failed permalinks:")
print("**{}**".format(checkList))
print("\n")
return False
else:
print("Passed!")
return True

paths = []
allPosts = []
postsWithNoName = []
postsWithTitle = []
allPermalinks = []
indexOverflow = []
postsWithNoThumbnail = []
temp = []
duplicatePermalinks = []
noTrailingSlash = []

categories = ["file_settings", "basic", "financial", "statistical", "scientific", "maps", "3d_charts", "multiple_axes"]
def check_postsWithNoName(meta_to_check):
failures = []
for meta in meta_to_check:
# Check #1 - do all non-redirect posts have names?
if "name" not in meta and "redirect_to" not in meta:
failures.append(post.metadata["permalink"])
return "do all non-redirect posts have names?", failures


def check_postsWithTitle(meta_to_check):
failures = []
for meta in meta_to_check:
# Check #2 - do any posts have titles?
if "title" in meta:
failures.append(post.metadata["permalink"])
return "do any posts have titles?", failures


def check_duplicatePermalinks(meta_to_check):
failures = []
allPermalinks = []
for meta in meta_to_check:
# Check #3 - are there duplicate permalinks/redirect_froms?
if "permalink" in meta and meta["permalink"] != "//plot.ly/products/dash/":
if meta["permalink"] in allPermalinks:
failures.append(meta["permalink"])
else:
allPermalinks.append(meta["permalink"])
if "redirect_from" in meta:
if meta["redirect_from"] in allPermalinks:
failures.append(meta["redirect_from"])
else:
allPermalinks.append(meta["redirect_from"])
return "are there posts with order > 5 and 'page_type: example_index'?", failures


def check_indexOverflow(meta_to_check):
failures = []
for meta in meta_to_check:
# Check #4 - are there posts with order > 5 and 'page_type: example_index'?
if "display_as" in meta and meta["display_as"] in categories:
if "language" in meta and meta["language"] in languages:
if "order" in meta and meta["order"] > 5:
if "page_type" in meta and meta["page_type"] == "example_index":
failures.append(meta["permalink"])
return "are there duplicate permalinks/redirect_froms?", failures


def check_postsWithNoThumbnail(meta_to_check):
failures = []
for meta in meta_to_check:
# Check #5 - does every post have a thumbnail?
if "thumbnail" not in meta:
if "display_as" in meta and meta["display_as"] in categories:
if "language" in meta and meta["language"] in languages:
failures.append(meta["permalink"])
return "does every post have a thumbnail?", failures


def check_noTrailingSlash(meta_to_check):
failures = []
for meta in meta_to_check:
# Check #6 - do any permalinks not end with a trailing slash?
if "permalink" in meta:
if meta["permalink"][-1] != "/":
failures.append(meta["permalink"])
return "do any permalinks not end with a trailing slash?", failures


categories = [
"file_settings",
"basic",
"financial",
"statistical",
"scientific",
"maps",
"3d_charts",
"multiple_axes",
]
languages = ["python", "python/v3", "plotly_js", "r"]

paths = []
if path == "r":
for suffix in ["Rmd"]:
paths += [x for x in Path(path).glob("*."+suffix)]
paths += [x for x in Path(path).glob("*." + suffix)]
else:
# collect all paths
# collect all paths
for suffix in ["md", "html"]:
paths += [x for x in Path(path).glob("**/*."+suffix)]
print("number posts:")
print (len(paths))
paths += [x for x in Path(path).glob("**/*." + suffix)]

# collect all posts
meta_to_check = []
for path in paths:
post = frontmatter.load(str(path))
if len(post.metadata.keys()) > 0:
allPosts.append(post)

# perform checks
for post in allPosts:
meta = post.metadata

# ignore posts with 'jupyter' in front-matter
if "jupyter" in meta:
continue

# Check #1 - do all non-redirect posts have names?
if "name" not in meta and "redirect_to" not in meta:
postsWithNoName.append(post.metadata['permalink'])

# Check #2 - do any posts have titles?
if "title" in meta:
postsWithTitle.append(post.metadata['permalink'])

# Check #3 - are there duplicate permalinks/redirect_froms?
if "permalink" in meta and meta['permalink'] != '//plot.ly/products/dash/':
allPermalinks.append(meta['permalink'])
if "redirect_from" in meta:
allPermalinks.append(meta['redirect_from'])

# Check #4 - are there posts with order > 5 and 'page_type: example_index'?
if "display_as" in meta and meta['display_as'] in categories:
if "language" in meta and meta['language'] in languages:
if "order" in meta and meta['order'] > 5:
if "page_type" in meta and meta['page_type'] == "example_index":
indexOverflow.append(meta['permalink'])

# Check #5 - does every post have a thumbnail?
if "thumbnail" not in meta:
if "display_as" in meta and meta['display_as'] in categories:
if "language" in meta and meta['language'] in languages:
postsWithNoThumbnail.append(meta['permalink'])

# Check #6 - do any permalinks not end with a trailing slash?
if "permalink" in meta:
if meta['permalink'][-1] != "/":
noTrailingSlash.append(meta['permalink'])


for post in allPermalinks:
if post in temp:
duplicatePermalinks.append(post)
continue
else:
temp.append(post)
if len(post.metadata.keys()) > 0 and "jupyter" not in post.metadata:
meta_to_check.append(post.metadata)


print("Begin CI Checks!\n")
passed_check_1 = ci_check(postsWithNoName, "do all non-redirect posts have names?")
passed_check_2 = ci_check(postsWithTitle, "do any posts have titles?")
passed_check_3 = ci_check(indexOverflow, "are there posts with order > 5 and 'page_type: example_index'?")
passed_check_4 = ci_check(duplicatePermalinks, "are there duplicate permalinks/redirect_froms?")
passed_check_5 = ci_check(postsWithNoThumbnail, "does every post have a thumbnail?")
passed_check_6 = ci_check(noTrailingSlash, "do any permalinks not end with a trailing slash?")
passed = True
check_functions = [v for k, v in globals().items() if k.startswith("check_")]
for check_function in check_functions:
message, failures = check_function(meta_to_check)
print("***********************************!")
print("Checking... {}".format(message))
if len(failures) > 0:
passed = False
print("NOT PASSED!\n")
print("List of failed permalinks:")
print("**{}**".format(failures))
print("\n")
else:
print("Passed!")
print("End CI Checks!\n")

if not passed_check_1 or not passed_check_2 or not passed_check_3 or not passed_check_4 or not passed_check_5 or not passed_check_6:
raise Exception("***********CI Checks Not Passed! Check Error Messages!*********************")
if not passed:
raise Exception("**One or more CI Check failed! Check Error Messages!")