def __init__(self, site, fp): id = path.splitext(path.join(*(_split_path(fp.name)[1:])))[0] Page.__init__(self, site, id, modified=util.filemtime(fp), tags=set(), summary='') data = fp.read().split('\n\n', 1) head = yaml.load(data.pop(0)) body = data and data.pop() or '' for key, val in head.items(): key = util.norm_key(key) self[key] = self.NORM.get(key, util.identity)(val) if self.date: self.update({ 'id': self._site.join_url(self.date.year, id, ext=False), 'template': self.template or 'entry', 'month_name': self.date.strftime('%B'), 'prevpost': None, 'nextpost': None, 'tags_by_count': lambda: sorted(self.tags.values(), key=Tag.sortkey_count), 'tags_by_name': lambda: sorted(self.tags.values(), key=Tag.sortkey_tag), }) if 'tags' in self._site: self['tags'] -= set((tag for tag in self.tags if tag not in self._site['tags'])) def _summary(m): summary = m.group(2).strip() self['summary'] = self.NORM['summary'](summary) return summary self['content'] = markdown(self.SUMMARY.sub(_summary, body).strip())
def __init__(self, site, fp): md = Markdown(extensions=["extra", "meta"]) id = path.splitext(path.join(*(_split_path(fp.name)[1:])))[0] Page.__init__(self, site, id, modified=util.filemtime(fp), tags=set(), summary="") data = fp.read() def _summary(m): summary = m.group(2).strip() self["summary"] = self.NORM["summary"](summary) return summary self["content"] = md.convert(self.SUMMARY.sub(_summary, data).strip()) head = md.Meta if not self["summary"]: soup = BeautifulSoup(self["content"]) self["summary"] = soup.first("p") for key, val in head.items(): key = util.norm_key(key) if len(val) == 1: val = val[0] try: self[key] = self.NORM.get(key, util.identity)(val) except: print data if self.date: self.update( { "id": id, "template": self.template or "entry", "month_name": self.date.strftime("%B"), "prevpost": None, "nextpost": None, "tags_by_count": lambda: sorted(self.tags.values(), key=Tag.sortkey_count), "tags_by_name": lambda: sorted(self.tags.values(), key=Tag.sortkey_tag), } ) if "tags" in self._site: self["tags"] -= set((tag for tag in self.tags if tag not in self._site["tags"]))