From 25e01d8bf2dadfc8a63d6cb37f1684a6f5dd217f Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Sun, 21 Jun 2020 19:55:51 +0200 Subject: [PATCH] Feat: import content task and pelicanconf --- content/pages/About.rst | 24 +++++++++ content/pages/Cours.rst | 9 ++++ pelicanconf.py | 80 +++++++--------------------- tasks.py | 115 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 168 insertions(+), 60 deletions(-) create mode 100644 content/pages/About.rst create mode 100644 content/pages/Cours.rst create mode 100644 tasks.py diff --git a/content/pages/About.rst b/content/pages/About.rst new file mode 100644 index 0000000..45fc58b --- /dev/null +++ b/content/pages/About.rst @@ -0,0 +1,24 @@ +À propos +######### + +:date: 2020-06-04 +:modified: 2020-06-04 +:authors: Benjamin Bertrand +:summary: À propos de ce site et de l'auteur. + +Ce site +======= + +Ce site est né après ma première année d'enseignement. Je quittais l'établissement où j'avais été stagiaire et où j'avais beaucoup travaillé avec mes collègues. L'idée était d'avoir un lieu où ce qui avait été fait pourrait être disponible et réutilisé. + +Aujourd'hui, il ne reste malheureusement pas grand chose de cette période à cause d'un travail d'édition trop important à réaliser pour le rendre publiable. Par contre la volonté d'avoir un lieu où tout ce que je produis pour mes cours est accessible à n'important qui est resté. + +Il m'a fallut plusieurs années avant de réussir à trouver une façon de m'organiser pour que l'édition ne soit pas un frein à la production documents mais une façon efficace de structurer et pérenniser mon travail. Ce site en est le résultat. + +Il repose sur une série de fichiers `reStructuredText `_ passé à la moulinette de `Pelican `_ pour produire le code HTML que vous voyez. Le tout est géré avec git et auto-hébergé pour garder un maximum d'indépendance. + +L'auteur +======== + + + diff --git a/content/pages/Cours.rst b/content/pages/Cours.rst new file mode 100644 index 0000000..fefe674 --- /dev/null +++ b/content/pages/Cours.rst @@ -0,0 +1,9 @@ +Mes cours +######### + +:date: 2020-06-04 +:modified: 2020-06-04 +:authors: Benjamin Bertrand +:summary: Accès à tous les documents pour mes cours + +Cours diff --git a/pelicanconf.py b/pelicanconf.py index 2a6f438..3b837f7 100644 --- a/pelicanconf.py +++ b/pelicanconf.py @@ -3,11 +3,11 @@ from __future__ import unicode_literals AUTHOR = 'Benjamin Bertrand' -SITENAME = 'OpyTex' -SITETITLE = 'OpyTex' -SITESUBTITLE = "Des cours de maths, d'info et un peu de réfléxions personnelles." -#SITEURL = 'opytex.org' +SITENAME = 'Opytex' +SITETITLE = 'Opytex' +SITESUBTITLE = '' SITEURL = '' +SITEDESCRIPTION = '' CC_LICENSE_COMMERCIAL = True CC_LICENSE = True @@ -27,23 +27,8 @@ PAGE_PATHS = ['pages'] #ARTICLE_PATHS = ['pages/Enseignement', 'Blog'] ARTICLE_PATHS = ['Enseignements'] STATIC_PATHS = ['./'] - INDEX_SAVE_AS = 'blog_index.html' -# Menu -MAIN_MENU = True -DISPLAY_PAGES_ON_MENU = False -DISPLAY_CATEGORIES_ON_MENU = False -MENUITEMS = [ - ('Opytex', "/opytex/"), - ("pyMath", "/pymath/"), - ("Enseignement", "/Enseignements"), - #('blog', '/blog_index.html'), - ('À propos', "/about.html"), - ('Archives', "/archives.html"), -] - - # Feed generation is usually not desired when developing FEED_ALL_ATOM = None CATEGORY_FEED_ATOM = None @@ -51,50 +36,25 @@ TRANSLATION_FEED_ATOM = None AUTHOR_FEED_ATOM = None AUTHOR_FEED_RSS = None +# Menu +MAIN_MENU = True +DISPLAY_PAGES_ON_MENU = False +DISPLAY_CATEGORIES_ON_MENU = False +MENUITEMS = [ + ('Opytex', "/opytex/"), + ("pyMath", "/pymath/"), + ("Contenus de cours", "/pages/mes-cours.html"), + #('blog', '/blog_index.html'), + ('À propos', "/pages/a-propos.html"), + #('Archives', "/pages/archives.html"), +] + # Blogroll -LINKS = ( - ('2019/2020', "/Enseignements/2019-2020/"), - ('2018/2019', "/Enseignements/2018-2019/"), - ('2017/2018', "/Enseignements/2017-2018/"), - ('2016/2017', "/Enseignements/2016-2017/"), - ('2015/2016', "/Enseignements/2015-2016/"), -) - +LINKS = () # Social widget -#SOCIAL = (('You can add links in your config file', '#'), -# ) +SOCIAL = () -DEFAULT_PAGINATION = 20 - -# Date -SHOW_DATE_MODIFIED = True -ARTICLE_ORDER_BY = "modified" - -DISPLAY_ARTICLE_INFO_ON_INDEX = True +DEFAULT_PAGINATION = 10 # Uncomment following line if you want document-relative URLs when developing #RELATIVE_URLS = True - -BOOTSTRAP_THEME = "flatly" -PLUGIN_PATHS = ['./plugins', './pelican-plugins'] - -PLUGINS = ['hierarchy', - 'tag_cloud', - "list_files", - "render_math", - "always_modified", - "pdf-img", - ] - -READERS = {"html": None} - -# hierarchy plugin config -ARTICLE_URL = 'Enseignements/{slug}/' -ARTICLE_SAVE_AS = 'Enseignements/{slug}/index.html' -#SLUGIFY_SOURCE = 'basename' -ARTICLE_NAVIGATION = True - - -TAGS_URL = "tags.html" -DISPLAY_TAGS_INLINE = True -DISPLAY_CATEGORIES_ON_SIDEBAR = True diff --git a/tasks.py b/tasks.py new file mode 100644 index 0000000..732748f --- /dev/null +++ b/tasks.py @@ -0,0 +1,115 @@ +# -*- coding: utf-8 -*- + +import os +import shutil +import sys +import datetime + +from invoke import task +from invoke.util import cd +from pelican.server import ComplexHTTPRequestHandler, RootedHTTPServer +from pelican.settings import DEFAULT_CONFIG, get_settings_from_file + +SETTINGS_FILE_BASE = 'pelicanconf.py' +SETTINGS = {} +SETTINGS.update(DEFAULT_CONFIG) +LOCAL_SETTINGS = get_settings_from_file(SETTINGS_FILE_BASE) +SETTINGS.update(LOCAL_SETTINGS) + +CONFIG = { + 'settings_base': SETTINGS_FILE_BASE, + 'settings_publish': 'publishconf.py', + # Output path. Can be absolute or relative to tasks.py. Default: 'output' + 'deploy_path': SETTINGS['OUTPUT_PATH'], + # Remote server configuration + 'ssh_user': 'sshcontent', + 'ssh_host': 'Embrevade', + 'ssh_port': '22', + 'ssh_path': '/var/www', + # Port for `serve` + 'port': 8000, +} + +@task +def clean(c): + """Remove generated files""" + if os.path.isdir(CONFIG['deploy_path']): + shutil.rmtree(CONFIG['deploy_path']) + os.makedirs(CONFIG['deploy_path']) + +@task +def build(c): + """Build local version of site""" + c.run('pelican -s {settings_base}'.format(**CONFIG)) + +@task +def rebuild(c): + """`build` with the delete switch""" + c.run('pelican -d -s {settings_base}'.format(**CONFIG)) + +@task +def regenerate(c): + """Automatically regenerate site upon file modification""" + c.run('pelican -r -s {settings_base}'.format(**CONFIG)) + +@task +def serve(c): + """Serve site at http://localhost:$PORT/ (default port is 8000)""" + + class AddressReuseTCPServer(RootedHTTPServer): + allow_reuse_address = True + + server = AddressReuseTCPServer( + CONFIG['deploy_path'], + ('', CONFIG['port']), + ComplexHTTPRequestHandler) + + sys.stderr.write('Serving on port {port} ...\n'.format(**CONFIG)) + server.serve_forever() + +@task +def reserve(c): + """`build`, then `serve`""" + build(c) + serve(c) + +@task +def preview(c): + """Build production version of site""" + c.run('pelican -s {settings_publish}'.format(**CONFIG)) + +@task +def livereload(c): + """Automatically reload browser tab upon file modification.""" + from livereload import Server + build(c) + server = Server() + # Watch the base settings file + server.watch(CONFIG['settings_base'], lambda: build(c)) + # Watch content source files + content_file_extensions = ['.md', '.rst'] + for extension in content_file_extensions: + content_blob = '{0}/**/*{1}'.format(SETTINGS['PATH'], extension) + server.watch(content_blob, lambda: build(c)) + # Watch the theme's templates and static assets + theme_path = SETTINGS['THEME'] + server.watch('{}/templates/*.html'.format(theme_path), lambda: build(c)) + static_file_extensions = ['.css', '.js'] + for extension in static_file_extensions: + static_file = '{0}/static/**/*{1}'.format(theme_path, extension) + server.watch(static_file, lambda: build(c)) + # Serve output path on configured port + server.serve(port=CONFIG['port'], root=CONFIG['deploy_path']) + + +@task +def publish(c): + """Publish to production via rsync""" + c.run('pelican -s {settings_publish}'.format(**CONFIG)) + c.run( + 'rsync --delete --exclude ".DS_Store" -pthrvz -c ' + '-e "ssh -p {ssh_port}" ' + '{} {ssh_user}@{ssh_host}:{ssh_path}'.format( + CONFIG['deploy_path'].rstrip('/') + '/', + **CONFIG)) +