-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathensurestuff.py
More file actions
executable file
·38 lines (32 loc) · 1021 Bytes
/
ensurestuff.py
File metadata and controls
executable file
·38 lines (32 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
from __future__ import print_function
import sys
import os
import re
r_markdownimage = re.compile(r'!\[.*?\]\((.*?)\)')
errors = []
posts = os.listdir('_posts')
for post in posts:
print(post)
fpath = os.path.join('_posts', post)
with open(fpath, 'rb') as fh:
for i,line in enumerate(fh):
if line.count('<img'):
# html image
if line.count('<img') != line.count('site.url'):
errors.append((
fpath,
'line {0}'.format(i),
'lacks {{ site.url }} prefix'))
m = r_markdownimage.findall(line)
for href in m:
if not href.count('site.url'):
errors.append((
fpath,
'line {0}'.format(i),
'lacks {{ site.url }} prefix'))
if errors:
print('Errors:')
for stuff in errors:
print(*stuff)
sys.exit(1)