Feat: Add personnal plugins
This commit is contained in:
1
plugins/list_files/__init__.py
Normal file
1
plugins/list_files/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .list_files import *
|
||||
40
plugins/list_files/list_files.py
Normal file
40
plugins/list_files/list_files.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from pelican import signals, contents
|
||||
from os import listdir, getcwd
|
||||
from os.path import isfile, join, sep, split
|
||||
from copy import copy
|
||||
from itertools import chain
|
||||
|
||||
'''
|
||||
This plugin creates a URL hierarchy for articles that matches the
|
||||
directory hierarchy of their sources.
|
||||
'''
|
||||
|
||||
def lsfiles(path):
|
||||
return [f for f in listdir(path) if isfile(join(path, f))]
|
||||
|
||||
def save_files(content_object):
|
||||
if type(content_object) is not contents.Article:
|
||||
return
|
||||
article = content_object
|
||||
path = split(article.get_relative_source_path())[0] + '/'
|
||||
path = path.replace(sep, '/' )
|
||||
abs_path = getcwd() + "/content/" + path
|
||||
|
||||
files = {i:(path+i) for i in lsfiles(abs_path)}
|
||||
try:
|
||||
fig_files = lsfiles(abs_path+"/fig")
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
else:
|
||||
fig_files = {i:(path+"fig/"+i) for i in fig_files}
|
||||
files.update(fig_files)
|
||||
|
||||
article.link_files = []
|
||||
|
||||
for i in files.items():
|
||||
article.link_files.append(i)
|
||||
|
||||
article.link_files.sort()
|
||||
|
||||
def register():
|
||||
signals.content_object_init.connect(save_files)
|
||||
Reference in New Issue
Block a user