diff options
-rw-r--r-- | config/config.py | 2 | ||||
-rw-r--r-- | config/generator.toml | 2 | ||||
-rw-r--r-- | generators/generators.py | 123 | ||||
-rw-r--r-- | source/index-fr.md | 41 | ||||
-rw-r--r-- | source/index.md | 28 |
5 files changed, 125 insertions, 71 deletions
diff --git a/config/config.py b/config/config.py index 144d0fbf..1d247166 100644 --- a/config/config.py +++ b/config/config.py @@ -28,6 +28,8 @@ RSS_ICON_HEIGHT = config["blog"]["RSS_ICON_HEIGHT"] #generator configurations GENERATOR_NAME = config["generator"]["GENERATOR_NAME"] GENERATOR_HOME_PAGE = config["generator"]["GENERATOR_HOME_PAGE"] +DEFAULTLANG = config["generator"]["DEFAULTLANG"] +LANGUAGES = config["generator"]["LANGUAGES"] SOURCEDIR = os.path.join(ROOTDIR, config["generator"]["SOURCEDIR"]) POSTSDIR = os.path.join(SOURCEDIR, config["generator"]["POSTSDIR"]) diff --git a/config/generator.toml b/config/generator.toml index 2ae0e83f..4b15d0a4 100644 --- a/config/generator.toml +++ b/config/generator.toml @@ -3,6 +3,8 @@ [generator] GENERATOR_NAME = "pyblog" GENERATOR_HOME_PAGE = "https://git.neodarz.net/neodarz/website/my_new_personal_website.git/about/" + DEFAULTLANG = "en" + LANGUAGES = ["en", "fr"] SOURCEDIR = "source" POSTSDIR = "blog" diff --git a/generators/generators.py b/generators/generators.py index 3122f9c8..c6cca082 100644 --- a/generators/generators.py +++ b/generators/generators.py @@ -304,63 +304,70 @@ def generate_notes_list(): def generate_index(feed): """Generate index.html from index.md and a TOC.""" + for language in LANGUAGES: + if language != DEFAULTLANG: + indexmdl = re.sub(r'index.md$', "index-{}.md".format(language), INDEXMD) + indexhtmll = re.sub(r'index.html$', "index-{}.html".format(language), INDEXHTML) + else: + indexmdl = INDEXMD + indexhtmll = INDEXHTML + + sys.stderr.write("generating index-{}.html\n".format(language)) + + # generate TOC + tocbuff = io.StringIO() + tocbuff.write('<div class="blog-index" id="toc">') + year = 10000 # will be larger than the latest year for quite a while + # recall that entries are in reverse chronological order + table_opened = False + for entry in feed.entries: + date = entry.updated_datetime + if date.year < year: + # close the previous table if there is one + if table_opened: + tocbuff.write(u'</table>\n') + # write a new <h2 class="blog-index-year-title"> tag with the smaller year + year = date.year + tocbuff.write(u'\n<h2 class="blog-index-year-title" id="{0}"><span class="left-h2">.:</span><span class="title-h2">{0}</span><span class="right-h2">:.</span></h2>\n\n'.format(year)) + tocbuff.write(u'<table class="blog-index-yearly-index">\n') + table_opened = True - sys.stderr.write("generating index.html\n") - - # generate TOC - tocbuff = io.StringIO() - tocbuff.write('<div class="blog-index" id="toc">') - year = 10000 # will be larger than the latest year for quite a while - # recall that entries are in reverse chronological order - table_opened = False - for entry in feed.entries: - date = entry.updated_datetime - if date.year < year: - # close the previous table if there is one - if table_opened: - tocbuff.write(u'</table>\n') - # write a new <h2 class="blog-index-year-title"> tag with the smaller year - year = date.year - tocbuff.write(u'\n<h2 class="blog-index-year-title" id="{0}"><span class="left-h2">.:</span><span class="title-h2">{0}</span><span class="right-h2">:.</span></h2>\n\n'.format(year)) - tocbuff.write(u'<table class="blog-index-yearly-index">\n') - table_opened = True - - # write a new table row entry in Markdown, in the format: - # - # <tr> - # <td class="blog-index-post-date"><time class="date" datetime="2015-05-05T00:06:04-0700">May 5</time></td> - # <td class="blog-index-post-title">[Blah blah](/blog/2015-05-04-blah-blah.html)</td> - # </tr> - monthday = date.strftime("%b %d") - tocbuff.write(u'<tr><td class="blog-index-post-date"><time class="date" datetime="%s">%s</time></td>' + # write a new table row entry in Markdown, in the format: + # + # <tr> + # <td class="blog-index-post-date"><time class="date" datetime="2015-05-05T00:06:04-0700">May 5</time></td> + # <td class="blog-index-post-title">[Blah blah](/blog/2015-05-04-blah-blah.html)</td> + # </tr> + monthday = date.strftime("%b %d") + tocbuff.write(u'<tr><td class="blog-index-post-date"><time class="date" datetime="%s">%s</time></td>' '<td class="blog-index-post-title">[%s](%s)</td></tr>\n' % (date.isoformat(), monthday, entry.title_text, entry.relpath)) - if table_opened: - tocbuff.write(u'</table>\n') - tocbuff.write('</div>') + if table_opened: + tocbuff.write(u'</table>\n') + tocbuff.write('</div>') - # create tempfile with index.md and the TOC concatenated, and generate index.html from that - # pylint: disable=invalid-name - fd, tmppath = tempfile.mkstemp() - os.close(fd) - with open(tmppath, 'w', encoding='utf-8') as tmpfile: - if os.path.exists(INDEXMD): - with open(INDEXMD, 'r', encoding='utf-8') as indexmd: - tmpfile.write(u"%s\n\n<hr>\n\n" % indexmd.read()) - tmpfile.write("%s\n" % tocbuff.getvalue()) - tocbuff.close() - - pandoc_args = [ - "pandoc", tmppath, - "--template", HTMLTEMPLATE, - "--highlight-style=pygments", - "-o", INDEXHTML, - ] - try: - subprocess.check_call(pandoc_args) - except subprocess.CalledProcessError: - sys.stderr.write("error: failed to generate index.html\n") - os.remove(tmppath) + # create tempfile with index.md and the TOC concatenated, and generate index.html from that + # pylint: disable=invalid-name + fd, tmppath = tempfile.mkstemp() + os.close(fd) + with open(tmppath, 'w', encoding='utf-8') as tmpfile: + if os.path.exists(indexmdl): + with open(indexmdl, 'r', encoding='utf-8') as indexmd: + tmpfile.write(u"%s\n\n<hr>\n\n" % indexmd.read()) + tmpfile.write("%s\n" % tocbuff.getvalue()) + tocbuff.close() + + pandoc_args = [ + "pandoc", tmppath, + "--template", HTMLTEMPLATE, + "--highlight-style=pygments", + "-o", indexhtmll, + ] + try: + subprocess.check_call(pandoc_args) + except subprocess.CalledProcessError: + sys.stderr.write("error: failed to generate index.html\n") + os.remove(tmppath) def generate_sitemap(feed): """Generate sitemap.xml.""" @@ -369,7 +376,7 @@ def generate_sitemap(feed): sitemap.append(utils.make_sitemap_url_element(BLOG_HOME, feed.updated, "daily", 1.0)) # other top level pages for name in os.listdir(BUILDDIR): - if (not name.endswith(".html") or name == "index.html" or + if (not name.endswith(".html") or re.match("index.*\.html", name) or re.match("google[a-z0-9]+\.html", name)): # exclude Google's site ownership verification file continue link = urllib.parse.urljoin(BLOG_HOME, name) @@ -799,7 +806,13 @@ def generate_blog(fresh=False, report_total_errors=True): max(fundamental_mtime, os.path.getmtime(srcpath)))): # new post or modified post anything_modified = True - if srcpath == INDEXMD: + indexmdlist = [] + for language in LANGUAGES: + if language != DEFAULTLANG: + indexmdlist.append("index-{}.md".format(language)) + else: + indexmdlist.append("index.md") + if srcpath in indexmdlist: continue # index will be processed separately if extension in ["css", "js", "asc", "html", "jpg", "png", "svg", "ico", "txt", "eot", "ttf", "woff", "woff2"]: diff --git a/source/index-fr.md b/source/index-fr.md new file mode 100644 index 00000000..949781d3 --- /dev/null +++ b/source/index-fr.md @@ -0,0 +1,41 @@ +--- +title: "Why is there always a cat on whatever you're editing?" +custom-css: " + .blog-index-year-title { + text-align: left; + } + + .blog-index-yearly-index { + margin-left: 1em; + } + + .blog-index td { + vertical-align: top; + } + + .blog-index-post-date { + width: 5em; + }" +--- + +Je m'apelle neodarz (alias Corentin Breton IRL), je suis développeur chez +Fullsave. + +Une question ? N'hésitez pas à me [contacter](/website/contact.html) +si vous êtes interressé ! + +Je stocke [ici](/notes.html) quelques trucs, jusqu'à maintenant en rapport avec +l'informatique, mais je me laisse librement le choix de poser des choses +qui n'ont rien à voir. :p + +Ça m'arrive aussi d'écrire des [articles](/blog) quand j'ai l'envie d'en prendre +le temps. + +Il m'arrive parfois de partager des liens qui arrivent dans mon agrégateur +de flux RSS via [shaarli](https://shaarli.neodarz.net). + +Je stocke aussi la plus part de mon code sur mon +[propre serveur](https://git.neodarz.net) ou parfois sur +[framagit](https://framagit.org/NeodarZ) (non pas github - +ça pue c'est pas libre :p) lorsque que le projet a pour +objectif d'être partagé. diff --git a/source/index.md b/source/index.md index 504b598f..06d22856 100644 --- a/source/index.md +++ b/source/index.md @@ -18,24 +18,20 @@ custom-css: " }" --- -Je m'apelle neodarz (alias Corentin Breton IRL), je suis développeur chez -Fullsave. +My name is neodarz (Corentin Breton IRL) and I'm developper at Fullsave a +French regional Telecom Operator. -Une question ? N'hésitez pas à me [contacter](/website/contact.html) -si vous êtes interressé ! +Question? Feel free to [contact](/website/contact.html) me if you want! -Je stocke [ici](/notes.html) quelques trucs, jusqu'à maintenant en rapport avec -l'informatique, mais je me laisse librement le choix de poser des choses -qui n'ont rien à voir. :p +I put [here](/notes.html) some things mainly about computers, but I keep me +free to write things who are not connected to this. :p -Ça m'arrive aussi d'écrire des [articles](/blog) quand j'ai l'envie d'en prendre -le temps. +Sometimes, when I want to, I write articles on my [blog](/blog). -Je stocke aussi la plus part de mon code sur mon -[propre serveur](https://git.neodarz.net) ou parfois sur -[framagit](https://framagit.org/NeodarZ) (non pas github - -ça pue c'est pas libre :p) lorsque que le projet a pour -objectif d'être partagé. +More time I will share links generaly via flux RSS on my [Shaarli](https://shaarli.neodarz.net) instance. -Il m'arrive parfois de partager des liens qui arrivent dans mon agrégateur -de flux RSS via [shaarli](https://shaarli.neodarz.net). +I also keep my code on my [personal git server](https://git.neodarz.net). I +also have some account on another account like +[Framagit](https://framagit.org/NeodarZ) or +[Github](https://github.com/NeodarZ), but it's mainly to contribute to anothers +projects. |