Package: c2p2
CodeCommitPushPublishLive and die by documentation.Matthew GinnardInstallationpipinstallc2p2orpipinstallgit+https://github.com/nanvel/c2p2.gitUsageFork c2p2_templateThe easiest way to start is to fork this template:https://github.com/nanvel/c2p2-template.Templates APIThe application looks for templates inside SOURCE_FOLDER, so we need to add them.
Minimal list of files required is:- site
    - engine
        - templates
            - 404.html
            - 500.html
            - index.html
            - page.html
            - label.html
            - sitemap.xmlindex.html,page.html,label.htmlandsitemap.xmlreceives, besidetornado standart template context,
variablec, that uses to access a list of pages and labels, for example:{{c.page}}{{c.page.title}}{{c.page.labels}}{{c.label}}{%forpageinc.pages%}{{c.pages['<page_slug>']}}{{c.pages.for_label('<label_slug>')}}c.pageis available only inpage.html.
It returns current page object.Pageobject has next attributes:urihtmlcreatedmodifiedtitlemetalabelspage.metareturnsPageMetaobject, where all variables specified in the top of the page is available.// page.md
created: 2015-10-10T00:00
show_comments: true
labels: Label1
        Label2// page.html{{c.page.meta.created}}-> '2015-10-10T00:00'{{c.page.meta.created}}-> '2015-10-10T00:00'{{c.page.meta.labels}}-> 'Label1'{{c.page.meta.get('labels')}}-> 'Label1'{{c.page.meta.get_list('labels')}}-> ['Label1', 'Label2']{{c.page.meta.show_comments}}-> true{{c.page.meta.not_exist}}-> Nonepage.labelsreturns list of Label objects connected to the page:{%forlabelinc.page.labels%}{{label.title}}{%end%}Labelobject has next attributes:titleslugc.pagesreturns an iterable that allows to get all pages list. Inlabel.htmlit return only pages belong to the label.
You also can get any page by uri usingc.pages.{%forpageinc.pages%}{{page.title}}{%end%}{{c.pages['2010/09/blog-post'].html}}{{c.pages.for_label('default')}}Running the serverTo run the application usesite/engine/app.py:importos.pathfromc2p2importappfromc2p2.settingsimportsettingsrel=lambdap:os.path.join(os.path.dirname(os.path.realpath(__file__)),p)if__name__=='__main__':settings.SOURCE_FOLDER=rel('..')app.run()SettingsThere are 4 ways to set settings:default settings (seec2p2/settings.py)environment variables withC2P2_prefix:export C2P2_PORT=5000command line arguments (app.py--PORT=5000)also you can change them directlysettings.PORT = 5000insite/engine/app.pyAvailable settings:DEBUG: Enable tornado debug modePORT: Port the app listening toSOURCE_FOLDER: Path to folder that contains pages sourceUPDATE_TIMEOUT: Number of seconds to rescan source folder. 0 - disableGITHUB_VALIDATE_IP: Enable GitHub ip validationGITHUB_SECRET: GitHub web hook secret, optionalGITHUB_BRANCH: GitHub branch to watchQuestions and AnswersRun locallycdsitevirtualenvvenv--no-site-packages-p/usr/local/bin/python3.5sourcevenv/bin/activatepipinstallc2p2pythonengine/app.pyOpenhttp://localhost:5000in browser.Update site if md file was changed without server restart (watch md files)Use UPDATE_TIMEOUT setting.Update site on GitHub pushCreate a new GitHub hook for your repository:url:http://mysite.com/pullsecret: should be equal to GITHUB_SECRET setting valueProduction configurationExample settings:DEBUG=falseUPDATE_TIMEOUT=0GITHUB_VALIDATE_IP=trueGITHUB_SECRET=<webhook secret>GITHUB_BRANCH=masterExample supervisor configuration:[program:mysite]
process_name=mysite
directory=/home/deploy/mysite
environment=C2P2_PORT=5100,C2P2_DEBUG=false,C2P2_UPDATE_TIMEOUT=0,C2P2_GITHUB_VALIDATE_ID=true,C2P2_GIHUB_SECRET=123xyz,C2P2_GITHUB_BRANCH=master
command=/home/deploy/mysite/venv/bin/python engine/app.py
user=deploy
stdout_logfile=/var/log/mysite/out.log
stderr_logfile=/var/log/mysite/err.log
autostart=true
autorestart=trueExample nginx configuration:upstreammysite{server127.0.0.1:5100;}server{listen80;# If you need to restrict access# auth_basic "Restricted";# auth_basic_user_file /etc/nginx/.htpasswd;server_namemysite.com;location/{proxy_cacheoff;proxy_passhttp://mysite;}location~*\.(?:css|png|jpe?g|gif|ico|zip|txt)${root/home/deploy/mysite;log_not_foundoff;}error_page500502503504/home/deploy/mysite/engine/templates/500.html;error_page400402403404/home/deploy/mysite/engine/templates/400.html;}Favicon and robots.txtJust add favicon.ico and robots.txt to root folder of your site.Custom md directivesIt is possible to register custom md directives:fromc2p2.utilsimportExtensionsRegistryExtensionsRegistry.register(extension=MyExtension)Edit on GitHub link<a href="https://github.com/nanvel/mysite/blob/master/{{c.page.uri}}.md" target="_blank">Edit on GitHub</a>Testspython-munittestc2p2.testsContributeIf you want to contribute to this project, please perform the following steps:# Fork this repository$virtualenv.env--no-site-packages-p/usr/local/bin/python3.5$source.env/bin/activate$pythonsetup.pyinstall$pipinstall-rrequirements.txt$gitbranchfeature_branchmaster# Implement your feature and tests$gitadd.&&gitcommit$gitpush-uoriginfeature_branch# Send me a pull request for your feature branch