def preBuild(site): global EVENTS global UPCOMING_EVENTS global PAST_EVENTS for event in site.pages(): if event.path.startswith(DIR): # Skip non html posts for obvious reasons if not event.path.endswith('.html'): continue # Parse headers and markdown body headers, body = parsePost(event) ctx = Context() ctx.update(headers) ctx['raw_body'] = body ctx['path'] = event.path ctx['url'] = event.absolute_final_url ctx['date_from'] = parseDate(headers.get('date_from')) ctx['date_to'] = parseDate(headers.get('date_to')) ctx['tags'] = headers.get('tags') and [h.strip() for h in headers['tags'].split(',')] or [] EVENTS.append(ctx) # Sort the posts by date today = datetime.today() EVENTS = sorted(EVENTS, key=lambda x: x['date_from']) EVENTS.reverse() PAST_EVENTS= filter(lambda x: x['date_to'] < today, EVENTS) UPCOMING_EVENTS = filter(lambda x: x['date_to'] >= today, EVENTS) UPCOMING_EVENTS.reverse()
def preBuild(site): global EVENTS global UPCOMING_EVENTS global PAST_EVENTS for event in site.pages(): if event.path.startswith(DIR): # Skip non html posts for obvious reasons if not event.path.endswith(".html"): continue # Parse headers and markdown body headers, body = parsePost(event.data()) ctx = Context() ctx.update(headers) ctx["raw_body"] = body ctx["path"] = event.path ctx["url"] = event.absolute_final_url ctx["date_from"] = parseDate(headers.get("date_from")) ctx["date_to"] = parseDate(headers.get("date_to")) ctx["tags"] = headers.get("tags") and [h.strip() for h in headers["tags"].split(",")] or [] EVENTS.append(ctx) # Sort the posts by date today = datetime.today() EVENTS = sorted(EVENTS, key=lambda x: x["date_from"]) EVENTS.reverse() PAST_EVENTS = list(filter(lambda x: x["date_to"] < today, EVENTS)) UPCOMING_EVENTS = list(filter(lambda x: x["date_to"] >= today, EVENTS)) UPCOMING_EVENTS.reverse()
def preBuild(site): global CASES # Build all the cases for case in site.pages(): if case.path.startswith(DIR): # Skip non html cases for obvious reasons if not case.path.endswith('.html'): continue # Parse headers and markdown body headers, body = parsePost(case.data()) # Build a context for each post caseContext = Context() caseContext.update(headers) caseContext['raw_body'] = body caseContext['path'] = case.path caseContext['date'] = parseDate(headers.get('date') or headers.get('created')) caseContext['url'] = case.absolute_final_url caseContext['tags'] = headers.get('tags') and [h.strip() for h in headers['tags'].split(',')] or [] caseContext['category'] = headers.get('category') and [h.strip() for h in headers['category'].split(',')] or [] CASES.append(caseContext) # Sort the cases by date CASES = sorted(CASES, key=lambda x: x['date']) CASES.reverse() indexes = range(0, len(CASES)) for i in indexes: if i+1 in indexes: CASES[i]['prev_post'] = CASES[i+1] if i-1 in indexes: CASES[i]['next_post'] = CASES[i-1]
def preBuild(site): global POSTS global NEWS_JSON global DEVELOPER_NEWS_JSON global CONFIG conf = os.path.join(site.path, 'config.json') CONFIG = json.load(open(conf, 'r')) # Build all the posts for page in site.pages(): if page.path.startswith(DIR): # Skip non html posts for obvious reasons if not page.path.endswith('.html'): continue # Parse headers and markdown body headers, body = parsePost(page) # Build a context for each post postContext = Context() postContext.update(headers) postContext['raw_body'] = body postContext['path'] = page.path postContext['date'] = parseDate( headers.get('date') or headers.get('created')) postContext['url'] = page.absolute_final_url postContext['tags'] = headers.get('tags') and [ h.strip() for h in headers['tags'].split(',') ] or [] postContext['category'] = headers.get('category') and [ h.strip() for h in headers['category'].split(',') ] or [] POSTS.append(postContext) # Sort the posts by date POSTS = sorted(POSTS, key=lambda x: x['date']) POSTS.reverse() indexes = xrange(0, len(POSTS)) for i in indexes: if i + 1 in indexes: POSTS[i]['prev_post'] = POSTS[i + 1] if i - 1 in indexes: POSTS[i]['next_post'] = POSTS[i - 1] NEWS_JSON = toDict(CONFIG, filterPosts(POSTS, 'news')) DEVELOPER_NEWS_JSON = toDict(CONFIG, filterPosts(POSTS, 'developernews'))
def preBuild(site): global EVENTS for event in site.pages(): if event.path.startswith(DIR): # Skip non html posts for obvious reasons if not event.path.endswith('.html'): continue # Parse headers and markdown body headers, body = parsePost(event) ctx = Context() ctx.update(headers) ctx['raw_body'] = body ctx['path'] = event.path ctx['url'] = event.absolute_final_url ctx['date_from'] = parseDate(headers.get('date_from')) ctx['date_to'] = parseDate(headers.get('date_to')) EVENTS.append(ctx) # Sort the posts by date EVENTS = sorted(EVENTS, key=lambda x: x['date_from']) EVENTS.reverse()
def preBuild(site): global POSTS global NEWS_JSON global DEVELOPER_NEWS_JSON global CONFIG conf = os.path.join(site.path, 'config.json') CONFIG = json.load(open(conf,'r')) # Build all the posts for page in site.pages(): if page.path.startswith(DIR): # Skip non html posts for obvious reasons if not page.path.endswith('.html'): continue # Parse headers and markdown body headers, body = parsePost(page) # Build a context for each post postContext = Context() postContext.update(headers) postContext['raw_body'] = body postContext['path'] = page.path postContext['date'] = parseDate(headers.get('date') or headers.get('created')) postContext['url'] = page.absolute_final_url postContext['tags'] = headers.get('tags') and [h.strip() for h in headers['tags'].split(',')] or [] postContext['category'] = headers.get('category') and [h.strip() for h in headers['category'].split(',')] or [] POSTS.append(postContext) # Sort the posts by date POSTS = sorted(POSTS, key=lambda x: x['date']) POSTS.reverse() indexes = xrange(0, len(POSTS)) for i in indexes: if i+1 in indexes: POSTS[i]['prev_post'] = POSTS[i+1] if i-1 in indexes: POSTS[i]['next_post'] = POSTS[i-1] NEWS_JSON = toDict(CONFIG, filterPosts(POSTS, 'news')) DEVELOPER_NEWS_JSON = toDict(CONFIG, filterPosts(POSTS, 'developernews'))
def to_datetime(headers): return parseDate(headers.get('date') or headers.get('created'))
def test_parseDate(self): self.assertEqual(type(utils.parseDate()), type(datetime.now())) self.assertEqual(type(utils.parseDate(None)), type(datetime.now())) fb = datetime.now() self.assertIs(utils.parseDate(None, fallback=fb), fb) self.assertIs(utils.parseDate(fallback=fb), fb) date_only = datetime(2016, 1, 22) dt_no_secs = datetime(2016, 1, 22, 13, 33) full_dt = datetime(2016, 1, 22, 13, 33, 37) # proper formatting self.assertEqual(utils.parseDate("{:%Y-%m-%d}".format(date_only)), date_only) self.assertEqual( utils.parseDate("{:%Y/%m/%d %H:%M:%S}".format(full_dt)), full_dt) self.assertEqual( utils.parseDate("{:%Y-%m-%dT%H:%M}".format(dt_no_secs)), dt_no_secs) # fallback is only used as a fallback self.assertIsNot( utils.parseDate("{:%Y-%m-%d}".format(date_only), fallback=fb), fb) # improper formatting self.assertIs(utils.parseDate("asdf", fallback=fb), fb) self.assertIs(utils.parseDate("", fallback=fb), fb) self.assertIs(utils.parseDate("12-12-12", fallback=fb), fb) # curious cases self.assertEqual(utils.parseDate("0012-12-12", fallback=fb), datetime(12, 12, 12)) self.assertEqual(utils.parseDate("1200-12-12", fallback=fb), datetime(1200, 12, 12)) with self.assertRaises(ValueError): utils.parseDate("0000-99-99")
def test_parseDate(self): self.assertEqual(type(utils.parseDate()), type(datetime.now())) self.assertEqual(type(utils.parseDate(None)), type(datetime.now())) fb = datetime.now() self.assertIs(utils.parseDate(None, fallback=fb), fb) self.assertIs(utils.parseDate(fallback=fb), fb) date_only = datetime(2016, 1, 22) dt_no_secs = datetime(2016, 1, 22, 13, 33) full_dt = datetime(2016, 1, 22, 13, 33, 37) # proper formatting self.assertEqual(utils.parseDate("{:%Y-%m-%d}".format(date_only)), date_only) self.assertEqual(utils.parseDate("{:%Y/%m/%d %H:%M:%S}".format(full_dt)), full_dt) self.assertEqual(utils.parseDate("{:%Y-%m-%dT%H:%M}".format(dt_no_secs)), dt_no_secs) # fallback is only used as a fallback self.assertIsNot(utils.parseDate("{:%Y-%m-%d}".format(date_only), fallback=fb), fb) # improper formatting self.assertIs(utils.parseDate("asdf", fallback=fb), fb) self.assertIs(utils.parseDate("", fallback=fb), fb) self.assertIs(utils.parseDate("12-12-12", fallback=fb), fb) # curious cases self.assertEqual(utils.parseDate("0012-12-12", fallback=fb), datetime(12, 12, 12)) self.assertEqual(utils.parseDate("1200-12-12", fallback=fb), datetime(1200, 12, 12)) with self.assertRaises(ValueError): utils.parseDate("0000-99-99")