summaryrefslogtreecommitdiff
path: root/jt
diff options
context:
space:
mode:
Diffstat (limited to 'jt')
-rwxr-xr-xjt49
1 files changed, 48 insertions, 1 deletions
diff --git a/jt b/jt
index 02a9bb8..22f05a6 100755
--- a/jt
+++ b/jt
@@ -36,6 +36,8 @@ template = '''\
[[!tag ]]
[[!meta date="%(date)s"]]
+%(topiclink)s
+
'''
@@ -115,10 +117,12 @@ class NewCommand(Command):
raise cliapp.AppException('Usage: journal-note new TITLE')
self._app.settings.require('source')
+ topic = self._app.settings['topic']
values = {
'title': args[0],
- 'date': time.strftime('%Y-%m-%d %H:%M')
+ 'date': time.strftime('%Y-%m-%d %H:%M'),
+ 'topiclink': self._get_topic_link(topic),
}
drafts_dir = DraftsDirectory(self._app.drafts_dir())
@@ -126,6 +130,12 @@ class NewCommand(Command):
draft_id = drafts_dir.create_draft(template % values)
self._app.edit_file(drafts_dir.get_draft_pathname(draft_id))
+ def _get_topic_link(self, topic):
+ if topic:
+ return 'Part of [[%s]]' % topic
+ else:
+ return ''
+
class ListCommand(Command):
@@ -235,6 +245,34 @@ class FinishCommand(Command):
cwd=self._app.settings['source'])
+class NewTopicCommand(Command):
+
+ def run(self, args):
+ if len(args) != 2:
+ raise cliapp.AppException(
+ 'Must be given two args (page path, title) (%r)' % args)
+
+ pathname = self._topic_pathname(args[0])
+ self._create_topic_page(pathname, args[1])
+ self._app.edit_file(pathname)
+
+ def _topic_pathname(self, page_path):
+ return os.path.join(self._app.settings['source'], page_path + '.mdwn')
+
+ def _create_topic_page(self, pathname, title):
+ dirname = os.path.dirname(pathname)
+ if not os.path.exists(dirname):
+ os.makedirs(dirname)
+
+ with open(pathname, 'w') as f:
+ f.write('''\
+[[!meta title="%(title)s"]]
+[[!inline pages="link(.)" archive=yes reverse=yes trail=yes]]
+''' % {
+ 'title': title,
+})
+
+
class NewPersonCommand(Command):
def run(self, args):
@@ -301,6 +339,11 @@ class JournalTool(cliapp.Application):
'push finished articles with git?')
self.settings.string(
+ ['topic'],
+ 'new entry belongs to TOPIC',
+ metavar='TOPIC')
+
+ self.settings.string(
['pretend-time'],
'pretend that the time is NOW (form: YYYY-MM-DD HH:MM:DD form)',
metavar='NOW')
@@ -329,6 +372,10 @@ class JournalTool(cliapp.Application):
'''Publish a draft journal entry.'''
FinishCommand(self).run(args)
+ def cmd_new_topic(self, args):
+ '''Create a new topic page.'''
+ NewTopicCommand(self).run(args)
+
def cmd_new_person(self, args):
'''Create a page to list all notes referring to a person.