示例#1
0
 def on_modified(self, event):
     if event.src_path.endswith(
             ".md"):
         print(f"Changes to {event.src_path}")
         dataobj = models.DataObj.from_file(event.src_path)
         search.add_to_index('dataobj', dataobj)
         self.last_modify_event = event.src_path
示例#2
0
    def insert(self):
        if self.validate():
            self.id = app.config["max_id"]
            data = {
                "type": self.type,
                "desc": self.desc,
                "title": str(self.title),
                "date": self.date.strftime("%x").replace("/", "-"),
                "tags": self.tags,
                "id": self.id,
                "path": self.path
            }
            if self.type == "bookmarks" or self.type == "pocket_bookmarks":
                data["url"] = self.url
            app.config["max_id"] += 1

            # convert to markdown
            dataobj = frontmatter.Post(self.content)
            dataobj.metadata = data
            create(frontmatter.dumps(dataobj),
                   str(self.id) + "-" + dataobj["date"] + "-" +
                   dataobj["title"],
                   path=self.path)
            print(add_to_index("dataobj", self))
            return self.id
        return False