added desc.txt

This commit is contained in:
gauthiier 2017-06-29 15:00:21 +02:00
parent 85bfef926c
commit 40ec5db009
2 changed files with 62 additions and 24 deletions

View File

@ -32,6 +32,15 @@ table td img {
.lst ul li { display: inline; } .lst ul li { display: inline; }
.lst ul li desc {
bborder: 10px grey ridge;
margin: 2em;
margin-bottom: 1em;
width: 985;
display: block;
}
.lst ul li img { .lst ul li img {
border: 10px grey ridge; border: 10px grey ridge;
margin: 2em; margin: 2em;

77
gen.py
View File

@ -57,34 +57,59 @@ content_map = {
'.txt': default '.txt': default
}; };
def index_content(dir_name, data_dir, index_txt, template): def index_content(dir_name, data_dir, index_txt, desc_txt, template):
print " indexing content -- " + dir_name;
# desc_txt is a markdown file containing description
# for the project - no layout applied to it, only md
if desc_txt:
try:
desc_file = open(desc_txt, 'r+');
desc_md = markdown.markdown(desc_file.read());
# transform markdown
except:
print "error opening description file: " + desc_txt;
desc_md = None;
#return;
# index_txt is a json file containing one thing: # index_txt is a json file containing one thing:
# an array of files names or glob patterns # an array of files names or glob patterns
print " indexing content -- " + dir_name; if index_txt:
try:
index_file = open(index_txt, 'r+');
content_index = json.loads(index_file.read());
except:
print "error opening index: " + index_txt;
content_index = None;
#return;
try: if desc_md == None and content_index == None:
index_file = open(index_txt, 'r+');
content_index = json.loads(index_file.read());
except:
print "error opening index: " + index_txt;
return; return;
files = [];
for i in content_index:
f = os.path.join(data_dir, i);
if os.path.isfile(f):
files.append(i);
else:
files += [os.path.basename(a) for a in glob.glob(f)];
content = "" content = ""
for j in files:
x, ext = os.path.splitext(j); if desc_md:
element = content_map[ext](j); content += "<li>" + "<desc>" + "\n" + desc_md + "</desc>" + "</li>" + "\n";
if element:
content += "<li>" + content_map[ext](j) + "</li>" + "\n"; if content_index:
files = [];
for i in content_index:
f = os.path.join(data_dir, i);
if os.path.isfile(f):
files.append(i);
else:
files += [os.path.basename(a) for a in glob.glob(f)];
for j in files:
x, ext = os.path.splitext(j);
element = content_map[ext](j);
if element:
content += "<li>" + content_map[ext](j) + "</li>" + "\n";
#print content #print content
@ -94,7 +119,7 @@ def index_content(dir_name, data_dir, index_txt, template):
#check if <Project Name>.txt exists (description file) #check if <Project Name>.txt exists (description file)
f = os.path.join(data_dir, "*.txt"); f = os.path.join(data_dir, "*.txt");
txt_files = [a for a in [os.path.basename(a) for a in glob.glob(f)] if a != 'index.txt']; txt_files = [a for a in [os.path.basename(a) for a in glob.glob(f)] if a != 'index.txt' and a != 'desc.txt'];
if len(txt_files) == 1: if len(txt_files) == 1:
fn = txt_files[0]; fn = txt_files[0];
link = '<li><a href="' + fn + '">' + fn + '</a></li>'; link = '<li><a href="' + fn + '">' + fn + '</a></li>';
@ -173,10 +198,14 @@ if __name__ == '__main__':
data_dir = os.path.join(dd, 'data'); data_dir = os.path.join(dd, 'data');
if os.path.isdir(data_dir): if os.path.isdir(data_dir):
#check if content needs index #check if content needs index -- index.txt is a json file
content_indx_txt = os.path.join(data_dir, 'index.txt'); content_indx_txt = os.path.join(data_dir, 'index.txt');
if os.path.isfile(content_indx_txt):
index_content(d, data_dir, content_indx_txt, content_index_template_str); #check if there is a description file -- desc.txt is a markdown file
content_desc_txt = os.path.join(data_dir, 'desc.txt');
if os.path.isfile(content_indx_txt) or os.path.isfile(content_desc_txt):
index_content(d, data_dir, content_indx_txt, content_desc_txt, content_index_template_str);
#copy content #copy content