Inspect metadata such as front matter, word count, etc. of markdown files.

get_meta[source]

get_meta(fname:str)

get metadata and front matter from fname.

assert get_meta('test_files/front_matter2.md')['mdseo-ignore'] == ['title', 'body', 'desc']
test_eq(get_meta('test_files/front_matter_test_docs.md'),
        {'fname': 'test_files/front_matter_test_docs.md',
         'n_words': 2,
         'key2': 'value2',
         'slug': 'custom/pathfor/site/this-is-waytoolong/wedontwantthis',
         'key': 'value',
         'mdseo-ignore': []}
       )

meta_list[source]

meta_list(srcdir:str)

Get list of all metadata for markdown files in srcdir.

assert len(meta_list('.')) > 1

find_dupe[source]

find_dupe(srcdir:str, key)

find duplicate values in front matter.

assert find_dupe('.', 'title')
assert not find_dupe('.', 'foo')

chk_dupe_title[source]

chk_dupe_title(srcdir:str='.')

Check for duplicate titles. Ignore with front matter mdseo-ignore: [dupe_title]

Type Default Details
srcdir str . directory of files to check
test_fail(chk_dupe_title)
assert not _min_len_err(_test_fm, 'description', 10000) #this is in mdeseo-ignore so rule is ignored
assert not _min_len_err(_test_fm, 'image', 10) # this key doesn't exist

assert len(_test_fm['slug']) == 19

assert _min_len_err(_test_fm, 'slug', 500) # 50 > 5
assert _max_len_err(_test_fm, 'slug', 5) # 19 > 5


assert not _min_len_err(_test_fm, 'slug', 5)
assert not _max_len_err(_test_fm, 'slug', 39)

_test_fm4 = get_meta('test_files/front_matter4.md')
assert not _max_len_err(_test_fm4, 'slug', 5) # because slug is in seo-ignore
assert not _min_len_err(_test_fm4, 'slug', 500) # because slug is in seo-ignore

chk_fm[source]

chk_fm(key:(description, slug, image, authors), srcdir:str='.', minlen:int=None, maxlen:int=None)

Check front matter for various rules. Ignore by setting front matter mdseo-ignore with the appropriate fields, for example `mdseo-ignore: ['slug']

Type Default Details
key (description, slug, image, authors) front matter field to check
srcdir str . directory of files to check
minlen int None the minimum character length allowed for the field
maxlen int None the maximum character length allowed for the field
test_fail(partial(chk_fm, key='description'))
test_fail(partial(chk_fm, key='authors'))

chk_len[source]

chk_len(n:int=50, srcdir:str='.')

Check if docs contain less than n words. Ignore with front matter mdseo-ignore: [length]

Type Default Details
n int 50 minimum number of words a document should contain
srcdir str . directory of files to check
test_fail(chk_len)