Skip to content

Commit eb5cfa0

Browse files
committed
adding wordpress instructions, check for description in post page, test command to generate posts, and removal of ? in filenames
Signed-off-by: Vanessa Sochat <[email protected]>
1 parent 3759a55 commit eb5cfa0

File tree

3 files changed

+55
-10
lines changed

3 files changed

+55
-10
lines changed

README.md

+33-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,19 @@ of what we collect:
2020
```
2121
2222
The tag must be unique (and this is tested), and the feed should be a format
23-
parseable by [feedparser](https://pythonhosted.org/feedparser/) (most are).
23+
parseable by [feedparser](https://pythonhosted.org/feedparser/) (most are).
24+
25+
#### Wordpress
26+
27+
WordPress is a common blogging platform, and so we include notes here for how
28+
to find a feed for your wordpress blog. If you want to include all content,
29+
you can usually find a main feed at `https://<yourblog>/feed/`. However, it's
30+
recommended to create a [tag or category](https://wordpress.org/support/article/wordpress-feeds/#categories-and-tags)
31+
feed, in which case you could find the feed at `https://<yourblog>/category/<category>/feed/`. See the linked
32+
page for more ways that you can generate custom feeds based on tags and categories.
33+
Once you've added your feed, it's recommended to test generate posts to ensure
34+
that it's parsed correctly. This is done during the continuous integration,
35+
but you can also do it locally (see below).
2436

2537
### 2. Generate Posts
2638

@@ -40,7 +52,26 @@ For this reason, we also define this in the context.
4052

4153
The reason this is set up to run with continuous integration is so that the site
4254
is regularly updated without human intervention. In the case that there is an error,
43-
the maintainers are notified.
55+
the maintainers are notified. However, you can test this generation locally, without
56+
generating any files!
57+
58+
```bash
59+
$ python script/generate_posts.py _data/authors.yml --output _posts/ --test
60+
```
61+
62+
It will show you any new folders and files generated without actually doing it.
63+
64+
```bash
65+
$ python script/generate_posts.py _data/authors.yml --output _posts/ --test
66+
[TEST] new author folder /home/vanessa/Documents/Dropbox/Code/usrse/blog/_posts/dsk
67+
Preparing new post: /home/vanessa/Documents/Dropbox/Code/usrse/blog/_posts/dsk/2019-4-22-p=1452.md
68+
Preparing new post: /home/vanessa/Documents/Dropbox/Code/usrse/blog/_posts/dsk/2019-2-5-p=1446.md
69+
Preparing new post: /home/vanessa/Documents/Dropbox/Code/usrse/blog/_posts/dsk/2019-1-23-p=1444.md
70+
Preparing new post: /home/vanessa/Documents/Dropbox/Code/usrse/blog/_posts/dsk/2018-9-26-p=1442.md
71+
Preparing new post: /home/vanessa/Documents/Dropbox/Code/usrse/blog/_posts/dsk/2018-6-27-p=1423.md
72+
Preparing new post: /home/vanessa/Documents/Dropbox/Code/usrse/blog/_posts/dsk/2018-6-25-p=1421.md
73+
Preparing new post: /home/vanessa/Documents/Dropbox/Code/usrse/blog/_posts/dsk/2018-2-8-p=1415.md
74+
```
4475

4576
## Development
4677

_layouts/post.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ <h2 class="subheading">{{ page.subtitle }}</h2>
3131
<div class="col-lg-8 col-md-10 mx-auto">
3232

3333
<p class="alert alert-primary">
34-
This is a crosspost from <a href="{{ page.blog_url }}">{{ page.blog_title }}</a>, {{ page.blog_subtitle }}.
34+
This is a crosspost from <a href="{{ page.blog_url }}">{{ page.blog_title }}</a>{% if page.blog_subtitle %}, {{ page.blog_subtitle }}{% endif %}.
3535
See the original post <a href="{{ page.original_url }}">here</a>.</p>
3636
</a>
3737

script/generate_posts.py

+21-7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ def get_parser():
3030
default=None, dest="output",
3131
help="The output folder to write posts.")
3232

33+
parser.add_argument("--test",
34+
default=False, dest="test",
35+
action='store_true',
36+
help="Test generation only (show files to be created)")
3337
return parser
3438

3539

@@ -61,14 +65,15 @@ def validate_authors(authors):
6165
return valid
6266

6367

64-
def parse_feeds(authors, output_dir):
68+
def parse_feeds(authors, output_dir, test=False):
6569
'''read in the list of authors, parse feeds and save results to a
6670
specified output directory.
6771
6872
Parameters
6973
==========
7074
authors: a list of authors, read in from an authors.yml
7175
output_dir: the output directory to write markdown posts to.
76+
test: don't write any files, only test generate
7277
'''
7378
if output_dir == None:
7479
print("Output directory must be defined.")
@@ -84,8 +89,11 @@ def parse_feeds(authors, output_dir):
8489
# Create output folder
8590
author_folder = os.path.join(output_dir, author['tag'])
8691
if not os.path.exists(author_folder):
87-
print("Creating new author folder %s" % author_folder)
88-
os.mkdir(author_folder)
92+
if test is False:
93+
print("Creating new author folder %s" % author_folder)
94+
os.mkdir(author_folder)
95+
else:
96+
print("[TEST] new author folder %s" % author_folder)
8997

9098
# Parse the feed, each entry is written to file based on title
9199
feed = feedparser.parse(author['feed'])
@@ -95,12 +103,15 @@ def parse_feeds(authors, output_dir):
95103

96104
# Write the file if it doesn't exist
97105
if not os.path.exists(markdown):
106+
98107
print('Preparing new post: %s' % markdown)
99108
post = generate_post(entry, author, feed)
100109

101-
# Write to file
102-
with open(markdown, 'w') as filey:
103-
filey.write(frontmatter.dumps(post))
110+
if test is False:
111+
112+
# Write to file
113+
with open(markdown, 'w') as filey:
114+
filey.write(frontmatter.dumps(post))
104115

105116

106117
def generate_post(entry, author, feed):
@@ -145,6 +156,9 @@ def get_markdown_file(author_folder, entry):
145156

146157
# The id is the last part of the url, lowercase
147158
title = [x for x in entry['id'].split('/') if x][-1].lower()
159+
160+
# Replace any variable names (? in wordpress) with -
161+
title = title.replace('?', '')
148162
filename = '%s-%s-%s-%s.md' %(year, month, day, title)
149163

150164
# The output markdown name is consistent
@@ -206,7 +220,7 @@ def help(return_code=0):
206220
print("Authors file %s is not valid." % authors)
207221

208222
# Generate outputs based on authors
209-
parse_feeds(authors, args.output)
223+
parse_feeds(authors, args.output, args.test)
210224

211225

212226
if __name__ == '__main__':

0 commit comments

Comments
 (0)