From 8446ed6c99ca6d878c61b3f5337298581830fd85 Mon Sep 17 00:00:00 2001 From: Joachim Nielandt Date: Thu, 4 Jan 2018 20:48:59 +0100 Subject: [PATCH] Added timestamps for real now. - python script puts them in the info.json files if not there yet - frontend shows it correctly --- src/app/components/post/post.component.html | 2 +- src/app/model/post.ts | 2 +- src/app/services/dataloader.service.ts | 4 +++- src/assets/post/blog/first/info.json | 4 +--- src/assets/post/project/cupboard1/info.json | 4 +--- src/assets/post/project/test/info.json | 4 +--- src/assets/post/tech/lxdarch/info.json | 4 +--- src/assets/posts.json | 2 +- src/scripts/compileposts.py | 20 ++++++++++++++------ 9 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/app/components/post/post.component.html b/src/app/components/post/post.component.html index 3b354f0..0aaf608 100644 --- a/src/app/components/post/post.component.html +++ b/src/app/components/post/post.component.html @@ -1,7 +1,7 @@
{{post.title}}
-
{{post.type}} {{post.lastmodified}}
+
{{post.type}} {{post.created_timestamp}}
\ No newline at end of file diff --git a/src/app/model/post.ts b/src/app/model/post.ts index e0b99ac..0b5cbe0 100644 --- a/src/app/model/post.ts +++ b/src/app/model/post.ts @@ -1,9 +1,9 @@ export class Post { - lastmodified: Date; type: string; title: any; id:String; + created_timestamp: Date; constructor(id:String) { this.id = id; diff --git a/src/app/services/dataloader.service.ts b/src/app/services/dataloader.service.ts index 7f35f07..e078c73 100644 --- a/src/app/services/dataloader.service.ts +++ b/src/app/services/dataloader.service.ts @@ -22,7 +22,9 @@ export class DataloaderService { let temp:Post = new Post(post.id); temp.title = post.info.title; temp.type = post.type; - temp.lastmodified = new Date(post.lastmodified*1000); + console.log('got this timestamp: '+post.info.created_timestamp); + temp.created_timestamp = new Date(post.info.created_timestamp*1000); + console.log('converted it to this: '+temp.created_timestamp); res.push(temp); } // console.log('these are the posts...'); diff --git a/src/assets/post/blog/first/info.json b/src/assets/post/blog/first/info.json index 7abe17e..b088614 100644 --- a/src/assets/post/blog/first/info.json +++ b/src/assets/post/blog/first/info.json @@ -1,3 +1 @@ -{ - "title":"Who said Web 1.0 was dead anyway?" -} \ No newline at end of file +{"created_timestamp": 1515094679.342938, "title": "Who said Web 1.0 was dead anyway?"} \ No newline at end of file diff --git a/src/assets/post/project/cupboard1/info.json b/src/assets/post/project/cupboard1/info.json index e49c1a7..5c425f1 100644 --- a/src/assets/post/project/cupboard1/info.json +++ b/src/assets/post/project/cupboard1/info.json @@ -1,3 +1 @@ -{ - "title":"cupboard" -} \ No newline at end of file +{"created_timestamp": 1515094644.215065, "title": "cupboard"} \ No newline at end of file diff --git a/src/assets/post/project/test/info.json b/src/assets/post/project/test/info.json index 13e2fec..115d6a7 100644 --- a/src/assets/post/project/test/info.json +++ b/src/assets/post/project/test/info.json @@ -1,3 +1 @@ -{ - "title": "Test title" -} \ No newline at end of file +{"created_timestamp": 1515094644.214663, "title": "Test title"} \ No newline at end of file diff --git a/src/assets/post/tech/lxdarch/info.json b/src/assets/post/tech/lxdarch/info.json index 9f75758..a5645d2 100644 --- a/src/assets/post/tech/lxdarch/info.json +++ b/src/assets/post/tech/lxdarch/info.json @@ -1,3 +1 @@ -{ - "title":"some things about lxc in arch" -} \ No newline at end of file +{"created_timestamp": 1515094644.215333, "title": "some things about lxc in arch"} \ No newline at end of file diff --git a/src/assets/posts.json b/src/assets/posts.json index e455f4b..9cc4ba6 100644 --- a/src/assets/posts.json +++ b/src/assets/posts.json @@ -1 +1 @@ -[{"info": {"title": "Test title"}, "lastmodified": 1514908964.183, "post": [], "type": "project", "id": "test"}, {"info": {"title": "cupboard"}, "lastmodified": 1514918689.4108193, "post": [], "type": "project", "id": "cupboard1"}, {"info": {"title": "some things about lxc in arch"}, "lastmodified": 1514918926.0, "post": [], "type": "tech", "id": "lxdarch"}, {"info": {"title": "Who said Web 1.0 was dead anyway?"}, "lastmodified": 1515009160.0915291, "post": [], "type": "blog", "id": "first"}] \ No newline at end of file +[{"info": {"created_timestamp": 1515094644.214663, "title": "Test title"}, "post": [], "type": "project", "id": "test"}, {"info": {"created_timestamp": 1515094644.215065, "title": "cupboard"}, "post": [], "type": "project", "id": "cupboard1"}, {"info": {"created_timestamp": 1515094644.215333, "title": "some things about lxc in arch"}, "post": [], "type": "tech", "id": "lxdarch"}, {"info": {"test": "some dummy value", "created_timestamp": 1515094679.342938, "title": "Who said Web 1.0 was dead anyway?"}, "post": [], "type": "blog", "id": "first"}] \ No newline at end of file diff --git a/src/scripts/compileposts.py b/src/scripts/compileposts.py index 68af682..96fb43f 100644 --- a/src/scripts/compileposts.py +++ b/src/scripts/compileposts.py @@ -1,5 +1,6 @@ import os; import json; +import time; # each folder in the post folder is a type of post base = '../assets/post' @@ -32,12 +33,19 @@ for type in types: temp['post'] = []; temp['info'] = d; - # figure out the last change of any file in the folder - lastchange = 0; - contents = os.listdir(postdir); - for contentfile in contents: - lastchange = max(lastchange,os.path.getmtime(postdir+"/"+contentfile)) - temp['lastmodified'] = lastchange; + # have to write the 'modified date' in the info.json of the post if it's not there yet + if not d.has_key('created_timestamp'): + d['created_timestamp'] = time.time() + # persist it in the json file itself + with open(infofile, 'w') as infooutfile: + json.dump(d, infooutfile) + + # # figure out the last change of any file in the folder + # lastchange = 0; + # contents = os.listdir(postdir); + # for contentfile in contents: + # lastchange = max(lastchange,os.path.getmtime(postdir+"/"+contentfile)) + # temp['lastmodified'] = lastchange; jsonresult.append(temp);