#!/usr/bin/env python3 # pelican-js: embed custom JavaScript easily # Copyright (C) 2017 Jorge Maldonado Ventura # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ Embed JavaScript files for Pelican ================================== This plugin allows you to easily embed JavaScript files in the header () or in the body () of individual articles or pages. The JavaScript files are embedded using the {2}' metadata['js'] = format_js(gen, metadata['js'], script) def move_resources(gen): """ Move JS files from js folder to output folder """ js_files = gen.get_files('js', extensions='js') js_dest = os.path.join(gen.output_path, 'vendor') copy_resources(gen.path, js_dest, js_files) def register(): """ Plugin registration """ signals.article_generator_context.connect(add_tags) signals.page_generator_context.connect(add_tags) signals.article_generator_finalized.connect(move_resources)