Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Cantaric committed Mar 25, 2024
0 parents commit a86a0a4
Show file tree
Hide file tree
Showing 39 changed files with 27,643 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/github-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to Pages

on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install lava-cactus package
run: |
pip install lava-cactus
sudo apt-get install gettext
# Build twice. Down't know why :) One time translate don't create translate correctly.
- name: Build Project with cactus
run: |
cactus build
cactus build
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
# Upload entire repository
path: './.build'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
233 changes: 233 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
# This is Your project README.md created by LavaCactus

## Main usage

You can change your site with django templates. After that just `build` to create static pages

cactus build

To start editing and previewing your site type the following. Then point your browser to localhost:8000 and start editing.
Cactus will automatically rebuild your project and refresh your browser on changes.

cactus serve

There is GihHub action to publish project to GitHub pages in `.github/workflow/github-pages.yml`.
You can delete or change it if you want.

## Extended guide

### Creating a new project

Project structure

- .build Generated site (upload this to your host)
- .github CI/CD github action to publish your site on github pages
- locale Instruction how to use translations if you need
- pages Your actual site pages
- about.html
- contact.html
- error.html A default 404 page
- index.html
- robots.txt
- sitemap.xml
- plugins A list of plugins. To enable remove disabled from the name
- static Directory with static assets
- css
- fonts
- images
- js
- templates Holds your django templates
- base.html
- config.json Configuration file

### Building your site

When you build your site it will generate a static version in the build folder that you can upload to any host.
Basically it will render each page from your pages folder, copy it over to the build folder and add all the static
assets to it so it becomes a self contained website. You can build your site like this:

cactus build

Your rendered website can now be found in the (hidden) [path]/.build folder. Cactus can also run a small webserver to
preview your site and update it when you make any changes. This is really handy when developing to get live visual feedback.

You can run it like this:

cactus serve

### Linking and contexts

Cactus makes it easy to relatively link to pages and static assets inside your project by using the template tags
{% static %} and {% url %}. For example if you are at page `/blog/2011/Jan/my-article.html` and would like to link to
`/contact.html` you would write the following:

<a href="{% url '/contact.html' %}">Contact</a>

Just use the URL you would normally use: don't forget the leading slash.

### Templates

Cactus uses the Django templates. They should be very similar to other templating systems and have some nice
capabilities like inheritance. In a nutshell: a variable looks like this `{{ name }}` and a tag like this
`{% block title %}Welcome{% endblock %}`. You can read the [full documentation][django_templates] at the django site.

### Enabling Plugins

To enable a plugin for your site, change the file name from [PLUGIN].disabled.py to [PLUGIN].py.

### Internationalization

#### Using internationalization with LavaCactus

To enable internationalization for your project:

1. Add a `use_translate` key to your configuration file
2. Add `default_language` key to your configuration file with main language. For example `default_language="en"`
3. Add `other_languages` key to your configuration file with the list of the other languages.
For example `other_languages=["ua", "ru"]`
4. Mark strings for translation in your site (using `{% trans %}`)
5. Put `{% load i18n %}` at the top of template with `trans` tags
6. Run `cactus messages:make`
7. Edit the .po file that was created with translations.
8. Run `cactus build` to create multilanguage site structure

### Deploying

Cactus can deploy your website directly to S3, all you need are your Amazon credentials and a bucket name. Cactus
remembers these in a configuration file name config.json to make future deploys painless. The secret key is stored
securely in the Keychain or similar services on other OSs.

cactus deploy

After deploying you can visit the website directly. Cactus also makes sure all your text files are compressed and adds caching headers.

### Extras

Modify `config.json` to set a custom blog path, default author name, or date pattern used to parse metadata. The defaults are:

"blog": {
"path": "blog",
"author": "Unknown",
"date-format": "%d-%m-%Y"
}

#### YAML Variables
By default you can declare variables to be included above each page, for example:

```
test_text: Lorem Ipsum
<p>{{ test_text }}</p>
```

You can declare the variables using YAML instead. Just surround the block with the `---`
and `...` [Document Separators](http://yaml.org/spec/1.1/#id857577). Then the objects
and arrays will be available inside the templates:

```
---
header_text: Lorem Ipsum
custom_object:
name: Lorem
description: Ipsum
custom_array:
-
name: lorem
-
name: ipsum
...
{% for item in custom_array %}
<p>{{ header_text }}: {{ item.name }}</p>
{% endfor %}
<p>{{ custom_object.name }} | {{ custom_object.description }}</p>
```

The *PyYAML* library is used for this functionality.

#### Asset pipeline

Cactus comes with an asset pipeline for your static files. If you'd like to use it, make sure you use the {% static %}
template tag to link to your static assets: they might be renamed in the process.


##### Fingerprinting

Modify `config.json`, and add the extensions you want to be fingerprinting:

"fingerprint": [
"js",
"css"
],

This lets you enable caching with long expiration dates. When a file changes, its name will reflect the change. Great for when you use a CDN.


##### Optimization

Modify `config.json`, and add the extensions you want to be optimizing:

"optimize": [
"js",
"css"
],


By default, Cactus will use:

+ YUI for CSS minification
+ Closure compiler for JS minification (YUI is built-in too, so you can use it!)

Check out `plugins/static_optimizes.py` in your project to understand how this works. It's very easy to add your own
optimizers!


#### Site URL

If you would like for your sitemap to have absolute paths you need to
add a site-url key to your config.json

You can enable this by adding modifying your configuration and adding:

"site-url": "http://yoursite.com",

Note that you need to do this if you want your sitemap to be valid for Google Webmaster Tools.


#### "Pretty" URLs

If you would like to not have ".html" in your URLs, Cactus can rewrite those for you, and make "/my-page.html" look
appear as "/my-page/", by creating the "/my-page/index.html" file.

You can enable this by adding modifying your configuration and adding:

"prettify": true

Note that if you're going to use this, you should definitely set your "Meta canonical" to the URL you're using so as
to not hurt your search rankings:

<link rel="canonical" href="{{ CURRENT_PAGE.absolute_final_url }}" />


#### Nameserver configuration

To set up a hosted zone and generate the correct nameserver records for your domain, make sure your bucket is a valid domain name, and run:

cactus domain:setup

Cactus will return with a set of nameservers that you can then enter with your registrar. To see the list again run:

cactus domain:list

If your domain is 'naked' (eg. without www), Cactus will add create an extra bucket that redirects the www variant of your domain to your naked domain (so www.lavacactus.com to cactus.com). All the above is Amazon only for now.


#### Extra files

Cactus will auto generate a `robots.txt` and `sitemap.xml` file for you based on your pages.

This will help bots to index your pages for Google and Bing for example.

[cactus_github_page]: https://github.com/eudicots/Cactus
[django_templates]: http://docs.djangoproject.com/en/dev/topics/templates/
3 changes: 3 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"prettify": true
}
15 changes: 15 additions & 0 deletions locale/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Internationalization

## Using internationalization with LavaCactus

To enable internationalization for your project:

1. Add a `use_translate` key to your configuration file
2. Add `default_language` key to your configuration file with main language. For example `default_language="en"`
3. Add `other_languages` key to your configuration file with the list of the other languages.
For example `other_languages=["ua", "ru"]`
4. Mark strings for translation in your site (using `{% trans %}`)
5. Put `{% load i18n %}` at the top of template with `trans` tags
6. Run `cactus messages:make`
7. Edit the .po file that was created with translations.
8. Run `cactus build` to create multilanguage site structure
31 changes: 31 additions & 0 deletions pages/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% extends "base.html" %}
{% block title %}
About
{% endblock %}

{% block body %}

<div class="text-center bg-body-tertiary">
<div class="container py-5">
<h1 class="text-body-emphasis">What is LavaCactus</h1>
<p class="col-lg-8 mx-auto lead">
LavaCactus is a simple but powerful static website generator using
Python and the <a href="https://docs.djangoproject.com/en/dev/topics/templates/" target="_blank">Django template system</a>. LavaCactus also makes it easy to develop
locally. It works great for company,
portfolio, personal, support websites and blogs.
</p>
<h2 class="text-body-emphasis">Examples</h2>
<p class="col-lg-8 mx-auto lead">
<ul class="list-group">
<li class="list-group-item"><a href="https://findsimilar.org" target="_blank">findsimilar.org</a></li>
<li class="list-group-item"><a href="https://lavacactus.craftsman.lol" target="_blank">This project website</a></li>
<li class="list-group-item"><a href="https://craftsman.lol" target="_blank">quill craftsman about website</a></li>
</ul>
</p>
<h2 class="text-body-emphasis">Project Status</h2>
<p class="col-lg-8 mx-auto lead">
This is Open Source project with BSD-3-Clause license
</p>
</div>
</div>
{% endblock %}
18 changes: 18 additions & 0 deletions pages/contact.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% extends "base.html" %}
{% block title %}
Contact
{% endblock %}

{% block body %}

<div class="text-center bg-body-tertiary rounded-3">
<img src="{% static 'images/logo.png' %}" class="bi mt-4 mb-3" width="100" height="100">
<h1 class="text-body-emphasis">Contact</h1>
<p class="col-lg-8 mx-auto fs-5 text-muted">
<ul class="list-group">
<li class="list-group-item"><a href="https://github.com/quillcraftsman/lavacactus/" target="_blank">Project on Github</a></li>
<li class="list-group-item"><a href="mailto:[email protected]">[email protected]</a></li>
</ul>
</p>
</div>
{% endblock %}
26 changes: 26 additions & 0 deletions pages/error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% extends "base.html" %}

{% block body %}
<div class="jumbotron">
<div class="container">
<h1>We're sorry!</h1>
<p>The page <b id="url"></b> could not be found on this server.</p>
</div>
</div>
{% endblock body %}

{% block scripts %}
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {

// Add the missing url to the text
$("#url").text(window.location.pathname);

// Fix the css locations dynamically
$("head link").each(function() {
for (var i=0; i<window.location.pathname.split(/\//g).length-2; i++)
$(this).attr("href", "../" + $(this).attr("href"));
});
})
</script>
{% endblock %}
Loading

0 comments on commit a86a0a4

Please sign in to comment.