|
10 | 10 | except:
|
11 | 11 | raise Exception("You need to specify a path that contains the files with front matter.")
|
12 | 12 |
|
13 |
| -def ci_check(checkList, error_message): |
14 |
| - print("***********************************!") |
15 |
| - print("Checking... {}".format(error_message)) |
16 |
| - if len(checkList) > 0: |
17 |
| - print("NOT PASSED!\n") |
18 |
| - print("List of failed permalinks:") |
19 |
| - print("**{}**".format(checkList)) |
20 |
| - print("\n") |
21 |
| - return False |
22 |
| - else: |
23 |
| - print("Passed!") |
24 |
| - return True |
25 | 13 |
|
26 |
| -paths = [] |
27 |
| -allPosts = [] |
28 |
| -postsWithNoName = [] |
29 |
| -postsWithTitle = [] |
30 |
| -allPermalinks = [] |
31 |
| -indexOverflow = [] |
32 |
| -postsWithNoThumbnail = [] |
33 |
| -temp = [] |
34 |
| -duplicatePermalinks = [] |
35 |
| -noTrailingSlash = [] |
| 14 | +def postsWithNoName(meta_to_check): |
| 15 | + failures = [] |
| 16 | + for meta in meta_to_check: |
| 17 | + # Check #1 - do all non-redirect posts have names? |
| 18 | + if "name" not in meta and "redirect_to" not in meta: |
| 19 | + failures.append(post.metadata['permalink']) |
| 20 | + return failures |
| 21 | + |
| 22 | +def postsWithTitle(meta_to_check): |
| 23 | + failures = [] |
| 24 | + for meta in meta_to_check: |
| 25 | + # Check #2 - do any posts have titles? |
| 26 | + if "title" in meta: |
| 27 | + failures.append(post.metadata['permalink']) |
| 28 | + return failures |
| 29 | + |
| 30 | +def duplicatePermalinks(meta_to_check): |
| 31 | + failures = [] |
| 32 | + allPermalinks = [] |
| 33 | + for meta in meta_to_check: |
| 34 | + # Check #3 - are there duplicate permalinks/redirect_froms? |
| 35 | + if "permalink" in meta and meta['permalink'] != '//plot.ly/products/dash/': |
| 36 | + if meta['permalink'] in allPermalinks: |
| 37 | + print(meta['permalink']) |
| 38 | + failures.append(meta['permalink']) |
| 39 | + else: |
| 40 | + allPermalinks.append(meta['permalink']) |
| 41 | + if "redirect_from" in meta: |
| 42 | + if meta['redirect_from'] in allPermalinks: |
| 43 | + failures.append(meta['redirect_from']) |
| 44 | + else: |
| 45 | + allPermalinks.append(meta['redirect_from']) |
| 46 | + return failures |
| 47 | + |
| 48 | + |
| 49 | +def indexOverflow(meta_to_check): |
| 50 | + failures = [] |
| 51 | + for meta in meta_to_check: |
| 52 | + # Check #4 - are there posts with order > 5 and 'page_type: example_index'? |
| 53 | + if "display_as" in meta and meta['display_as'] in categories: |
| 54 | + if "language" in meta and meta['language'] in languages: |
| 55 | + if "order" in meta and meta['order'] > 5: |
| 56 | + if "page_type" in meta and meta['page_type'] == "example_index": |
| 57 | + failures.append(meta['permalink']) |
| 58 | + return failures |
| 59 | + |
| 60 | +def postsWithNoThumbnail(meta_to_check): |
| 61 | + failures = [] |
| 62 | + for meta in meta_to_check: |
| 63 | + # Check #5 - does every post have a thumbnail? |
| 64 | + if "thumbnail" not in meta: |
| 65 | + if "display_as" in meta and meta['display_as'] in categories: |
| 66 | + if "language" in meta and meta['language'] in languages: |
| 67 | + failures.append(meta['permalink']) |
| 68 | + return failures |
| 69 | + |
| 70 | +def noTrailingSlash(meta_to_check): |
| 71 | + failures = [] |
| 72 | + for meta in meta_to_check: |
| 73 | + # Check #6 - do any permalinks not end with a trailing slash? |
| 74 | + if "permalink" in meta: |
| 75 | + if meta['permalink'][-1] != "/": |
| 76 | + failures.append(meta['permalink']) |
| 77 | + return failures |
| 78 | + |
| 79 | +checks = { |
| 80 | + "do all non-redirect posts have names?": postsWithNoName, |
| 81 | + "do any posts have titles?": postsWithTitle, |
| 82 | + "are there posts with order > 5 and 'page_type: example_index'?": indexOverflow, |
| 83 | + "are there duplicate permalinks/redirect_froms?": duplicatePermalinks, |
| 84 | + "does every post have a thumbnail?": postsWithNoThumbnail, |
| 85 | + "do any permalinks not end with a trailing slash?": noTrailingSlash, |
| 86 | +} |
36 | 87 |
|
37 | 88 | categories = ["file_settings", "basic", "financial", "statistical", "scientific", "maps", "3d_charts", "multiple_axes"]
|
38 | 89 | languages = ["python", "python/v3", "plotly_js", "r"]
|
39 | 90 |
|
| 91 | +paths = [] |
40 | 92 | if path == "r":
|
41 | 93 | for suffix in ["Rmd"]:
|
42 | 94 | paths += [x for x in Path(path).glob("*."+suffix)]
|
43 | 95 | else:
|
44 |
| - # collect all paths |
| 96 | + # collect all paths |
45 | 97 | for suffix in ["md", "html"]:
|
46 | 98 | paths += [x for x in Path(path).glob("**/*."+suffix)]
|
47 |
| -print("number posts:") |
48 |
| -print (len(paths)) |
49 | 99 |
|
50 | 100 | # collect all posts
|
| 101 | +meta_to_check = [] |
51 | 102 | for path in paths:
|
52 | 103 | post = frontmatter.load(str(path))
|
53 |
| - if len(post.metadata.keys()) > 0: |
54 |
| - allPosts.append(post) |
55 |
| - |
56 |
| -# perform checks |
57 |
| -for post in allPosts: |
58 |
| - meta = post.metadata |
59 |
| - |
60 |
| - # ignore posts with 'jupyter' in front-matter |
61 |
| - if "jupyter" in meta: |
62 |
| - continue |
63 |
| - |
64 |
| - # Check #1 - do all non-redirect posts have names? |
65 |
| - if "name" not in meta and "redirect_to" not in meta: |
66 |
| - postsWithNoName.append(post.metadata['permalink']) |
67 |
| - |
68 |
| - # Check #2 - do any posts have titles? |
69 |
| - if "title" in meta: |
70 |
| - postsWithTitle.append(post.metadata['permalink']) |
71 |
| - |
72 |
| - # Check #3 - are there duplicate permalinks/redirect_froms? |
73 |
| - if "permalink" in meta and meta['permalink'] != '//plot.ly/products/dash/': |
74 |
| - allPermalinks.append(meta['permalink']) |
75 |
| - if "redirect_from" in meta: |
76 |
| - allPermalinks.append(meta['redirect_from']) |
77 |
| - |
78 |
| - # Check #4 - are there posts with order > 5 and 'page_type: example_index'? |
79 |
| - if "display_as" in meta and meta['display_as'] in categories: |
80 |
| - if "language" in meta and meta['language'] in languages: |
81 |
| - if "order" in meta and meta['order'] > 5: |
82 |
| - if "page_type" in meta and meta['page_type'] == "example_index": |
83 |
| - indexOverflow.append(meta['permalink']) |
84 |
| - |
85 |
| - # Check #5 - does every post have a thumbnail? |
86 |
| - if "thumbnail" not in meta: |
87 |
| - if "display_as" in meta and meta['display_as'] in categories: |
88 |
| - if "language" in meta and meta['language'] in languages: |
89 |
| - postsWithNoThumbnail.append(meta['permalink']) |
90 |
| - |
91 |
| - # Check #6 - do any permalinks not end with a trailing slash? |
92 |
| - if "permalink" in meta: |
93 |
| - if meta['permalink'][-1] != "/": |
94 |
| - noTrailingSlash.append(meta['permalink']) |
95 |
| - |
96 |
| - |
97 |
| -for post in allPermalinks: |
98 |
| - if post in temp: |
99 |
| - duplicatePermalinks.append(post) |
100 |
| - continue |
101 |
| - else: |
102 |
| - temp.append(post) |
| 104 | + if len(post.metadata.keys()) > 0 and "jupyter" not in post.metadata: |
| 105 | + meta_to_check.append(post.metadata) |
| 106 | + |
| 107 | + |
103 | 108 |
|
104 | 109 | print("Begin CI Checks!\n")
|
105 |
| -passed_check_1 = ci_check(postsWithNoName, "do all non-redirect posts have names?") |
106 |
| -passed_check_2 = ci_check(postsWithTitle, "do any posts have titles?") |
107 |
| -passed_check_3 = ci_check(indexOverflow, "are there posts with order > 5 and 'page_type: example_index'?") |
108 |
| -passed_check_4 = ci_check(duplicatePermalinks, "are there duplicate permalinks/redirect_froms?") |
109 |
| -passed_check_5 = ci_check(postsWithNoThumbnail, "does every post have a thumbnail?") |
110 |
| -passed_check_6 = ci_check(noTrailingSlash, "do any permalinks not end with a trailing slash?") |
| 110 | +passed = True |
| 111 | +for message in checks: |
| 112 | + failures = checks[message](meta_to_check) |
| 113 | + print("***********************************!") |
| 114 | + print("Checking... {}".format(message)) |
| 115 | + if len(failures) > 0: |
| 116 | + passed = False |
| 117 | + print("NOT PASSED!\n") |
| 118 | + print("List of failed permalinks:") |
| 119 | + print("**{}**".format(failures)) |
| 120 | + print("\n") |
| 121 | + else: |
| 122 | + print("Passed!") |
111 | 123 | print("End CI Checks!\n")
|
112 | 124 |
|
113 |
| -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: |
| 125 | +if not passed: |
114 | 126 | raise Exception("***********CI Checks Not Passed! Check Error Messages!*********************")
|
0 commit comments