Skip to content

Commit 42b9553

Browse files
authored
Fix: change frontmatter library (#10)
* fix: change frontmatter library * chore: update docker base image
1 parent f56ae66 commit 42b9553

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

validator/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3
1+
FROM python:3-slim
22

33
RUN mkdir data
44

validator/requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
decorator==4.4.2
2-
-e git+https://github.com/jonbeebe/frontmatter.git@accd644b15a5ac7adaab261655eb552065020821#egg=frontmatter
3-
PyYAML==5.1
1+
decorator==5.0.7
2+
python-frontmatter==1.0.0
3+
PyYAML==5.4.1
44
six==1.15.0
55
validators==0.18.2

validator/validate.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /usr/bin/python
22
# -*- coding: utf-8 -*-
33
import os, sys, glob, re, validators, argparse
4-
from frontmatter import Frontmatter
4+
import frontmatter
55

66
# Parse arguments
77
parser = argparse.ArgumentParser()
@@ -24,27 +24,33 @@
2424
link_err_str = "\n{err}\n File: {file}\n Line: {line}\n Link: {link}\n"
2525
id_err_str = "\nError: {err}\n id: {id}\n Files:\n {f1}\n {f2}\n"
2626

27+
def render_fmatter(fm):
28+
s = ''
29+
for k in fm.keys():
30+
s += '\n'+f"{k}: {fm[k]}"
31+
return s+'\n'
32+
2733
def check_frontmatter(fmatter):
2834
num_errs = 0
2935
has_required_attrs = True
30-
fm = fmatter['frontmatter'].replace('\n','\n ')
36+
fm = render_fmatter(fmatter).replace('\n','\n ')
3137
for x in required_attrs:
32-
if x not in fmatter['attributes']: # Check for required attributes
38+
if x not in fmatter.keys(): # Check for required attributes
3339
print(attr_err_str.format(file=fname, attr=x, err="missing", fm=fm))
3440
has_required_attrs = False
3541
num_errs += 1
3642

3743
# Skip the rest of checks if missing required attributes
3844
if has_required_attrs:
39-
if not re.match('^[-\w]+$', fmatter['attributes']["id"]): # Check for invalid id string
45+
if not re.match('^[-\w]+$', fmatter["id"]): # Check for invalid id string
4046
print(attr_err_str.format(file=fname, attr="id", err="invalid\n id must contain only alphanumeric, hyphen(-), or underscore(_)", fm=fm))
4147
num_errs += 1
4248

43-
if fmatter['attributes']["title"] is None: # Check for empty attribute
49+
if fmatter["title"] is None: # Check for empty attribute
4450
print(attr_err_str.format(file=fname, attr="title", err="invalid", fm=fm))
4551
num_errs += 1
4652

47-
if not isinstance(fmatter['attributes']["is_entry_point"] , bool) : # Check for non-boolean attribute
53+
if not isinstance(fmatter["is_entry_point"] , bool) : # Check for non-boolean attribute
4854
print(attr_err_str.format(file=fname, attr="is_entry_point", err="invalid", fm=fm))
4955
num_errs += 1
5056

@@ -61,11 +67,11 @@ def check_frontmatter(fmatter):
6167
continue
6268

6369
# Parse file's front matter
64-
fmatter = Frontmatter.read_file(fname)
70+
fmatter = frontmatter.load(fname)
6571
err = check_frontmatter(fmatter)
6672
errs += err
6773
if err == 0:
68-
id = fmatter['attributes']["id"]
74+
id = fmatter['id']
6975
if id in dict: # Check if id already exists
7076
print(id_err_str.format(err="id already exists", id=id, f1=dict[id]["filename"], f2=fname))
7177
errs += 1

0 commit comments

Comments
 (0)