From 08c553942c6342cbabc2f04331ca9e6780e03aba Mon Sep 17 00:00:00 2001 From: Jean Jordaan Date: Sun, 9 Feb 2020 10:14:51 +0700 Subject: [PATCH 01/12] Add translation support --- get_posts_from_notion.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/get_posts_from_notion.py b/get_posts_from_notion.py index 7a2fda6f..150ee4c2 100644 --- a/get_posts_from_notion.py +++ b/get_posts_from_notion.py @@ -17,12 +17,14 @@ continue # Handle Frontmatter - text = """--- -title: %s -date: %s -description: + text = f"""--- +title: {post.title} +date: {post.created} +summary: {post.summary} +slug: {post.slug} +lang: {post.language} --- -""" % (post.title, datetime.datetime.now()) +""" # Handle Title text = text + '\n\n' + '# ' + post.title + '\n\n' for content in post.children: From 2de9e820342956a27bac3be34366bf3e30e20eed Mon Sep 17 00:00:00 2001 From: Jean Jordaan Date: Sun, 9 Feb 2020 10:17:31 +0700 Subject: [PATCH 02/12] Switch to Python 3.6 for f-string support --- runtime.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime.txt b/runtime.txt index 5a958026..d70c8f8d 100644 --- a/runtime.txt +++ b/runtime.txt @@ -1 +1 @@ -3.5 +3.6 From 3d201c7d097e777883435e5c51d4b479b79a5707 Mon Sep 17 00:00:00 2001 From: Jean Jordaan Date: Sun, 9 Feb 2020 10:20:13 +0700 Subject: [PATCH 03/12] No Python 3.6 on Netlify? Switch back to %-interpolation --- get_posts_from_notion.py | 14 +++++++------- runtime.txt | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/get_posts_from_notion.py b/get_posts_from_notion.py index 150ee4c2..e985b42d 100644 --- a/get_posts_from_notion.py +++ b/get_posts_from_notion.py @@ -17,14 +17,14 @@ continue # Handle Frontmatter - text = f"""--- -title: {post.title} -date: {post.created} -summary: {post.summary} -slug: {post.slug} -lang: {post.language} + text = """--- +title: %s +date: %s +summary: %s +slug: %s +lang: %s --- -""" +""" % (post.title, post.created, post.summary, post.slug, post.language) # Handle Title text = text + '\n\n' + '# ' + post.title + '\n\n' for content in post.children: diff --git a/runtime.txt b/runtime.txt index d70c8f8d..5a958026 100644 --- a/runtime.txt +++ b/runtime.txt @@ -1 +1 @@ -3.6 +3.5 From 578c370b7e4a10fef589ae92401cd83d718bb672 Mon Sep 17 00:00:00 2001 From: Jean Jordaan Date: Sun, 9 Feb 2020 11:41:32 +0700 Subject: [PATCH 04/12] Split posts/pages; fix support for translation --- get_posts_from_notion.py | 106 +++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/get_posts_from_notion.py b/get_posts_from_notion.py index e985b42d..0cfca4ec 100644 --- a/get_posts_from_notion.py +++ b/get_posts_from_notion.py @@ -8,61 +8,61 @@ from notion.client import NotionClient CLIENT = NotionClient(token_v2=os.environ["NOTION_TOKEN"]) -BLOG_HOME = CLIENT.get_block(os.environ["NOTION_BLOG_POSTS_PAGE"]) +NOTION_BLOG_POSTS = CLIENT.get_block(os.environ["NOTION_BLOG_POSTS"]) +NOTION_PAGES = CLIENT.get_block(os.environ["NOTION_PAGES"]) -# Main Loop -for post in BLOG_HOME.children: - if not post.type == 'page': - print("Skipping", post) - continue +def get_pages(table, outdir): + # Main Loop + for page in table.collection.get_rows(): + print(page) + if not page.type == 'page': + print("Skipping", page) + continue - # Handle Frontmatter - text = """--- -title: %s -date: %s -summary: %s -slug: %s -lang: %s ---- -""" % (post.title, post.created, post.summary, post.slug, post.language) - # Handle Title - text = text + '\n\n' + '# ' + post.title + '\n\n' - for content in post.children: - # Handles H1 - if content.type == 'header': - text = text + '# ' + content.title + '\n\n' - # Handles H2 - elif content.type == 'sub_header': - text = text + '## ' + content.title + '\n\n' - # Handles H3 - elif content.type == 'sub_sub_header': - text = text + '### ' + content.title + '\n\n' - # Handles Code Blocks - elif content.type == 'code': - text = text + '```\n' + content.title + '\n```\n\n' - # Handles Images - elif content.type == 'image': - text = text + '![' + content.id + '](' + content.source + ')\n\n' - # Handles Bullets - elif content.type == 'bulleted_list': - text = text + '* ' + content.title + '\n' - # Handles Dividers - elif content.type == 'divider': - text = text + '---' + '\n\n' - # Handles Basic Text, Links, Single Line Code - elif content.type == 'text': - text = text + content.title + '\n\n' - else: - print("Ignoring unknown block", content) + # Handle Frontmatter + text = """--- + title: %s + date: %s + summary: %s + slug: %s + lang: %s + --- + """ % (page.title, page.created, page.summary, page.slug, page.language) + # Handle Title + text = text + '\n\n' + '# ' + page.title + '\n\n' + for content in page.children: + # Handles H1 + if content.type == 'header': + text = text + '# ' + content.title + '\n\n' + # Handles H2 + elif content.type == 'sub_header': + text = text + '## ' + content.title + '\n\n' + # Handles H3 + elif content.type == 'sub_sub_header': + text = text + '### ' + content.title + '\n\n' + # Handles Code Blocks + elif content.type == 'code': + text = text + '```\n' + content.title + '\n```\n\n' + # Handles Images + elif content.type == 'image': + text = text + '![' + content.id + '](' + content.source + ')\n\n' + # Handles Bullets + elif content.type == 'bulleted_list': + text = text + '* ' + content.title + '\n' + # Handles Dividers + elif content.type == 'divider': + text = text + '---' + '\n\n' + # Handles Basic Text, Links, Single Line Code + elif content.type == 'text': + text = text + content.title + '\n\n' + else: + print("Ignoring unknown block", content) + with open('./content/%s/%s%s.md' % (outdir, page.slug, '-%s'%page.language if page.language else ''), 'w') as page: + page.write(text) + print('Wrote A New Page') + print(text) - title = post.title.replace(' ', '-') - title = title.replace(',', '') - title = title.replace(':', '') - title = title.replace(';', '') - title = title.lower() - with open('./content/blog/' + title + '.md', 'w') as post: - post.write(text) - print('Wrote A New Page') - print(text) +get_pages(NOTION_PAGES, 'pages') +get_pages(NOTION_BLOG_POSTS, 'blog') From d3097f39fef15e222e57b79a3279ddef304e9df6 Mon Sep 17 00:00:00 2001 From: Jean Jordaan Date: Sun, 9 Feb 2020 11:56:34 +0700 Subject: [PATCH 05/12] Fix page indentation --- get_posts_from_notion.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/get_posts_from_notion.py b/get_posts_from_notion.py index 0cfca4ec..6985a018 100644 --- a/get_posts_from_notion.py +++ b/get_posts_from_notion.py @@ -21,13 +21,13 @@ def get_pages(table, outdir): # Handle Frontmatter text = """--- - title: %s - date: %s - summary: %s - slug: %s - lang: %s - --- - """ % (page.title, page.created, page.summary, page.slug, page.language) +title: %s +date: %s +summary: %s +slug: %s +lang: %s +--- +""" % (page.title, page.created, page.summary, page.slug, page.language) # Handle Title text = text + '\n\n' + '# ' + page.title + '\n\n' for content in page.children: From ee90d18c590cf488d5514cb324e1376d467507e4 Mon Sep 17 00:00:00 2001 From: Jean Jordaan Date: Sun, 9 Feb 2020 12:00:45 +0700 Subject: [PATCH 06/12] Log less --- get_posts_from_notion.py | 1 - 1 file changed, 1 deletion(-) diff --git a/get_posts_from_notion.py b/get_posts_from_notion.py index 6985a018..c575862d 100644 --- a/get_posts_from_notion.py +++ b/get_posts_from_notion.py @@ -61,7 +61,6 @@ def get_pages(table, outdir): with open('./content/%s/%s%s.md' % (outdir, page.slug, '-%s'%page.language if page.language else ''), 'w') as page: page.write(text) print('Wrote A New Page') - print(text) get_pages(NOTION_PAGES, 'pages') From 6e6d67707e3cb3ac6c834e9ea4ff0362ee06022b Mon Sep 17 00:00:00 2001 From: Jean Jordaan Date: Sun, 9 Feb 2020 12:07:18 +0700 Subject: [PATCH 07/12] Fix default content Can't mix translated and un-translated pages --- content/pages/.posts_from_notion_go_here | 0 content/pages/{about.md => about-en.md} | 21 +++++++------- content/pages/signup.html | 35 ------------------------ 3 files changed, 10 insertions(+), 46 deletions(-) create mode 100644 content/pages/.posts_from_notion_go_here rename content/pages/{about.md => about-en.md} (84%) delete mode 100644 content/pages/signup.html diff --git a/content/pages/.posts_from_notion_go_here b/content/pages/.posts_from_notion_go_here new file mode 100644 index 00000000..e69de29b diff --git a/content/pages/about.md b/content/pages/about-en.md similarity index 84% rename from content/pages/about.md rename to content/pages/about-en.md index 03943cd1..bf7dc9be 100644 --- a/content/pages/about.md +++ b/content/pages/about-en.md @@ -1,7 +1,9 @@ --- title: About -date: 2019-11-08 16:03:19.190894 -description: +date: 2019-10-04 12:47:00 +summary: +slug: about +lang: en --- @@ -9,17 +11,16 @@ description: PyCon Thailand is a community effort driven by the members of the Python Community in Bangkok and the entire organising team are all volunteers. PyCon thailand is run as a Non-profit event and any money made from ticket sales or sponsorship is put back into this or future events to grow the community. -PyCon Thailand sets itself apart from other many other developer events in Thailand by being both non-profit and by having an affordable ticket price. The event can be a professional conference that provides valuable training and networking to companies. PyCon Thailand also provides financial support to the non-professional Python community of Thailand. +PyCon Thailand sets itself apart from other many other developer events in Thailand by being both non-profit and by having an affordable ticket price. The event can be a professional conference that provides valuable training and networking to companies. Pycon Thailand also provides financial support to non-professinal Python community of Thailand. -## About Python +## __*About Python*__ * Python is an open source programming language. * \#1 learning language in USA universities * \#3 most popular developer language in the world * Used by organisations such as Google, Wikipedia, CERN, NASA, Facebook, Instagram and Spotify. * Popularly used for Web Development, Artificial Intelligence, DevOps, Scientific Research and Data Analytics. - -## About PyCon +## __*About PyCon*__ * PyCon (US) One of the top developer conferences * Established in 2003 @@ -28,16 +29,14 @@ PyCon Thailand sets itself apart from other many other developer events in Thail * Hosted in 45 different countries. * Supported and attended by the world’s top technology organisations. * Key topics include Data Analytics, Machine Learning, Science, Robotics, Web Development, DevOps, Internet of Things, Gaming and Databases. - -## The People +## __*The People*__ Pycon attracts people from all over the world. Pycon is one of the largest open source language developer conference in Thailand. In Pycon 2018, 83% attendees are from Thailand and 17% of the international attendees are well represented by South-east Asian countries. Many people traveled from the USA and all over Europe to attend too. This is because Thailand is also a well-known for it's good food, culture and climate. Attendees are entrepreneurs, developers, educators, engineers and young aspiring Python users. What they all have in common is a passion for the programming language, Python. They come to discover, meet people, learn stuff, have fun, and be inspired. -## PyCon Thailand History +## __*PyCon Thailand History*__ -* 2020: We will be doubling in size again! * 2019: will be bigger and better -* 2018: Sold out event for over 200 attendees. See [Archive](https://2018.th.pycon.org/) and last year's talks on youtube. +* 2018: Sold out event for over 200 attendees. See Archive and last years talks on youtube. * 2017: PyCon thailand team concieved and started organising * 2015: ThaiPy bangkok monthly started diff --git a/content/pages/signup.html b/content/pages/signup.html deleted file mode 100644 index 9da6a1a6..00000000 --- a/content/pages/signup.html +++ /dev/null @@ -1,35 +0,0 @@ - - - Newsletter signup - - - - - - - - -

Sign up for our newsletter

-

We will post occasional updates about what's coming up at the conference. -

- - - -
-
-
- - - - -
-
-
-
- - - From 306b4d2cfd257b5c80ca41eca51d33c88d13a78e Mon Sep 17 00:00:00 2001 From: Jean Jordaan Date: Sun, 9 Feb 2020 12:17:17 +0700 Subject: [PATCH 08/12] Make pages translatable --- theme/templates/page.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/theme/templates/page.html b/theme/templates/page.html index d286783a..5c0c6641 100644 --- a/theme/templates/page.html +++ b/theme/templates/page.html @@ -41,6 +41,8 @@

Contents

{% endif %} + {% import '_includes/translations.html' as translations with context %} + {{ translations.translations_for(page) }} {{ page.content }} {% from '_includes/comments.html' import comments_section with context %} {{ comments_section(page) }} From 209b63f93269aa83ba2ac37a4e99e2424c1ef819 Mon Sep 17 00:00:00 2001 From: Jean Jordaan Date: Sun, 9 Feb 2020 22:05:31 +0700 Subject: [PATCH 09/12] Add language names, in addition to the codes --- pelicanconf.py | 7 ++++++- theme/templates/_includes/translations.html | 12 ++++++++++-- theme/templates/article.html | 5 +++++ theme/templates/page.html | 8 ++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/pelicanconf.py b/pelicanconf.py index 74db17c7..d9a3e17e 100644 --- a/pelicanconf.py +++ b/pelicanconf.py @@ -4,7 +4,7 @@ AUTHOR = 'Tech WG' SITENAME = 'PyCon Thailand 2020' -SITEURL = '' +SITEURL = 'https://th.pycon.org' PATH = 'content' @@ -12,6 +12,11 @@ DEFAULT_LANG = 'en' +LANGUAGE_CODES = { + 'en': 'English', + 'th': 'ไทย', + } + THEME = 'theme' # Feed generation is usually not desired when developing diff --git a/theme/templates/_includes/translations.html b/theme/templates/_includes/translations.html index 473bf1fb..f4bf1563 100644 --- a/theme/templates/_includes/translations.html +++ b/theme/templates/_includes/translations.html @@ -1,9 +1,17 @@ +{% macro entry_hreflang(entry) %} +{% if entry.translations %} + {% for translation in entry.translations %} + + {% endfor %} +{% endif %} +{% endmacro %} + {% macro translations_for(article) %} {% if article.translations %}

-This post is also available in: +This content is also available in: {% for translation in article.translations|sort(attribute = 'lang') %} - {{ translation.lang }}{% if loop.index0 + 2 == loop.length %} and{% elif not loop.last %}, {% endif %} + {{ LANGUAGE_CODES[translation.lang] }}{% if loop.index0 + 2 == loop.length %} and{% elif not loop.last %}, {% endif %} {% endfor %}

{% endif %} diff --git a/theme/templates/article.html b/theme/templates/article.html index 9e31d187..c5d6137b 100644 --- a/theme/templates/article.html +++ b/theme/templates/article.html @@ -26,6 +26,11 @@ {% block head_links %} {{ super() }} {% include '_includes/photos_header.html' %} + +{% import 'translations.html' as translations with context %} +{% if translations.entry_hreflang(article) %} + {{ translations.entry_hreflang(article) }} +{% endif %} {% endblock head_links %} {% block content %} diff --git a/theme/templates/page.html b/theme/templates/page.html index 5c0c6641..db0ddc37 100644 --- a/theme/templates/page.html +++ b/theme/templates/page.html @@ -20,6 +20,14 @@ {{ smo_metadata(page) }} {% endblock meta_tags_in_head %} +{% block head_links %} +{{ super() }} +{% import 'translations.html' as translations with context %} +{% if translations.entry_hreflang(page) %} + {{ translations.entry_hreflang(page) }} +{% endif %} +{% endblock head_links %} + {% block content %}
From 5ebefdfa1720ba85a9104472bf25889941d6288c Mon Sep 17 00:00:00 2001 From: Jean Jordaan Date: Tue, 11 Feb 2020 16:14:58 +0700 Subject: [PATCH 10/12] `make publish` to use publishconf.py on netlify --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 815e8313..db245a28 100644 --- a/build.sh +++ b/build.sh @@ -4,4 +4,4 @@ pelican-themes -i theme python get_posts_from_notion.py # Build the site -make html +make publish From 50385647b1331ccfd7d9f9e70306f1083e07fddf Mon Sep 17 00:00:00 2001 From: Jean Jordaan Date: Tue, 11 Feb 2020 16:18:17 +0700 Subject: [PATCH 11/12] The about.md page was just a sample, delete it Content comes from Notion. The `about-en.md` page got picked up as a rename of the sample `about.md` page, but it's just confusing. --- content/pages/about-en.md | 43 --------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 content/pages/about-en.md diff --git a/content/pages/about-en.md b/content/pages/about-en.md deleted file mode 100644 index bf7dc9be..00000000 --- a/content/pages/about-en.md +++ /dev/null @@ -1,43 +0,0 @@ ---- -title: About -date: 2019-10-04 12:47:00 -summary: -slug: about -lang: en ---- - - -# About - -PyCon Thailand is a community effort driven by the members of the Python Community in Bangkok and the entire organising team are all volunteers. PyCon thailand is run as a Non-profit event and any money made from ticket sales or sponsorship is put back into this or future events to grow the community. - -PyCon Thailand sets itself apart from other many other developer events in Thailand by being both non-profit and by having an affordable ticket price. The event can be a professional conference that provides valuable training and networking to companies. Pycon Thailand also provides financial support to non-professinal Python community of Thailand. - -## __*About Python*__ - -* Python is an open source programming language. -* \#1 learning language in USA universities -* \#3 most popular developer language in the world -* Used by organisations such as Google, Wikipedia, CERN, NASA, Facebook, Instagram and Spotify. -* Popularly used for Web Development, Artificial Intelligence, DevOps, Scientific Research and Data Analytics. -## __*About PyCon*__ - -* PyCon (US) One of the top developer conferences -* Established in 2003 -* Official conference of the Python community. -* More than 50 regular PyCon events run globally. -* Hosted in 45 different countries. -* Supported and attended by the world’s top technology organisations. -* Key topics include Data Analytics, Machine Learning, Science, Robotics, Web Development, DevOps, Internet of Things, Gaming and Databases. -## __*The People*__ - -Pycon attracts people from all over the world. Pycon is one of the largest open source language developer conference in Thailand. In Pycon 2018, 83% attendees are from Thailand and 17% of the international attendees are well represented by South-east Asian countries. Many people traveled from the USA and all over Europe to attend too. This is because Thailand is also a well-known for it's good food, culture and climate. Attendees are entrepreneurs, developers, educators, engineers and young aspiring Python users. What they all have in common is a passion for the programming language, Python. They come to discover, meet people, learn stuff, have fun, and be inspired. - -## __*PyCon Thailand History*__ - -* 2019: will be bigger and better -* 2018: Sold out event for over 200 attendees. See Archive and last years talks on youtube. -* 2017: PyCon thailand team concieved and started organising -* 2015: ThaiPy bangkok monthly started - - From 0c924d4fdaf0928b0f2a11158affc23a7e38ebfa Mon Sep 17 00:00:00 2001 From: Jean Jordaan Date: Tue, 11 Feb 2020 16:19:31 +0700 Subject: [PATCH 12/12] Netlify will `make publish` which uses publishconf.py --- pelicanconf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pelicanconf.py b/pelicanconf.py index d9a3e17e..c055a745 100644 --- a/pelicanconf.py +++ b/pelicanconf.py @@ -4,7 +4,7 @@ AUTHOR = 'Tech WG' SITENAME = 'PyCon Thailand 2020' -SITEURL = 'https://th.pycon.org' +SITEURL = '' PATH = 'content'