git ssb

0+

Grey the earthling / scuttleblog



Commit 97b4322a22f2f3f94e18226935df02c45daa7d39

Make several lines shorter, rearrange small chunks of code

Greg K Nicholson committed on 10/15/2017, 10:52:30 PM
Parent: 285357d39779c5b508eeb5aa4a655ee87c847a25

Files changed

scuttleblog.pychanged mode from 100644 to 100755
scuttleblog.pyView
@@ -48,36 +48,46 @@
4848 '-c', 'this.value.content.type == "post"', \
4949 '-c', 'this.value.content.text != null', \
5050 '-c', 'this.value.content.text != ""', \
5151 '-c', 'this.value.content.root == null']
52- user_posts_stream = subprocess.Popen(user_posts_args, stdout = subprocess.PIPE)
53- user_posts_json = subprocess.check_output(json_posts_args, stdin = user_posts_stream.stdout)
52 + user_posts_stream = subprocess.Popen(user_posts_args,
53 + stdout = subprocess.PIPE)
54 + user_posts_json = subprocess.check_output(json_posts_args,
55 + stdin = user_posts_stream.stdout)
5456 user_posts = json.loads(user_posts_json)
5557 return user_posts
5658
5759 def define_post_text(text):
5860 text = text.strip()
5961 title = text.splitlines()[0]
6062 if re.match('#', text):
61- # The first line is a heading. Use it as the title and strip it from the body.
62- body = ''.join(text.splitlines(keepends=True)[1:]).strip() \
63- if len(text.splitlines()) > 1 \
64- else ''
63 + # The first line is a heading.
64 + # Use it as the title and strip it from the body.
65 + if len(text.splitlines()) > 1:
66 + body = ''.join(text.splitlines(keepends=True)[1:]).strip()
67 + else:
68 + body = ''
6569 else:
66- # Truncate the first line and use it as the title. Keep everything in the body.
70 + # Truncate the first line and use it as the title.
71 + # Keep everything in the body.
6772 maxlength = 100
6873 ellipsis = '...'
69- title = title if len(title) <= maxlength else title[:maxlength].rsplit(' ', 1)[0] + ellipsis
74 + if len(title) > maxlength:
75 + title = title[:maxlength].rsplit(' ', 1)[0] + ellipsis
7076 body = text
7177 title = re.sub('^#+\s+', '', title)
7278 return {'title': title, 'body': body}
7379
7480 def build_post_structure(p):
7581 post = {}
7682 post['frontmatter'] = {}
7783 post['frontmatter']['key'] = p['key']
78- post['frontmatter']['title'] = define_post_text(p['value']['content']['text'])['title']
79- post['frontmatter']['date'] = datetime.datetime.fromtimestamp(int(p['value']['timestamp'] / 1000), datetime.timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')
84 + post['frontmatter']['title'] = define_post_text(
85 + p['value']['content']['text'])['title']
86 + time = datetime.datetime.fromtimestamp(int(p['value']['timestamp']
87 + / 1000),
88 + datetime.timezone.utc)
89 + post['frontmatter']['date'] = time.strftime('%Y-%m-%dT%H:%M:%SZ')
8090 post['frontmatter']['sequence'] = p['value']['sequence']
8191 post['body'] = define_post_text(p['value']['content']['text'])['body']
8292 return (post)
8393
@@ -89,9 +99,8 @@
8999 return content
90100
91101 def define_post_filename(post):
92102 folder = 'hugo/content/posts'
93- #slug = post['key'].replace('+','-').replace('/','_').replace('=.sha256','')
94103 slug = str(post['frontmatter']['sequence'])
95104 filetype = 'md'
96105 return folder + '/' + slug + '.' + filetype
97106
@@ -106,19 +115,27 @@
106115 write_post_file(build_post_structure(post))
107116
108117
109118 def get_user_metadata(ssb_userid):
110- user_metadata_args = ['sbot', 'links', '--source', ssb_userid, '--dest', ssb_userid, '--rel', 'about', '--values']
111- json_metadata_args = ['json', '--deep-merge', '-c', 'this.value.content.type == "about"']
112- user_metadata_stream = subprocess.Popen(user_metadata_args, stdout = subprocess.PIPE)
113- user_metadata_json = subprocess.check_output(json_metadata_args, stdin = user_metadata_stream.stdout)
119 + user_metadata_args = ['sbot', 'links',
120 + '--source', ssb_userid,
121 + '--dest', ssb_userid,
122 + '--rel', 'about',
123 + '--values']
124 + json_metadata_args = ['json', '--deep-merge',
125 + '-c', 'this.value.content.type == "about"']
126 + user_metadata_stream = subprocess.Popen(user_metadata_args,
127 + stdout = subprocess.PIPE)
128 + user_metadata_json = subprocess.check_output(json_metadata_args,
129 + stdin = user_metadata_stream.stdout)
114130 user_metadata = json.loads(user_metadata_json)
115131 return user_metadata
116132
117133 def check_hugo_theme(theme, theme_clone_url):
118134 hugo_theme_dir = os.path.join(scuttleblog_dir, 'hugo', 'themes', theme)
119135 if not os.path.isdir(hugo_theme_dir):
120- subprocess.run(['git', 'submodule', 'add', '-f', theme_clone_url, hugo_theme_dir])
136 + subprocess.run(['git', 'submodule', 'add', '-f',
137 + theme_clone_url, hugo_theme_dir])
121138
122139 def build_hugo_config(m):
123140 hugo_config = {}
124141 hugo_config['baseurl'] = conf.hugo_baseurl
@@ -126,9 +143,10 @@
126143 if 'name' in m['value']['content']:
127144 hugo_config['title'] = m['value']['content']['name']
128145 hugo_config['params'] = {}
129146 if 'description' in m['value']['content']:
130- hugo_config['params']['subtitle'] = m['value']['content']['description'].replace('\n', ' ')
147 + description = m['value']['content']['description']
148 + hugo_config['params']['subtitle'] = description.replace('\n', ' ')
131149 return (hugo_config)
132150
133151 def write_hugo_config_from_user(ssb_userid):
134152 metadata = get_user_metadata(ssb_userid)

Built with git-ssb-web