A Template for everithing

🏠 flvbox.org

πŸ¦„ Emacs Org Mode Overview

Org mode was first released by Carsten Dominik in 2004 as an outlining and project planning tool. Further development turned it into a general tool that can be used to author professional documents like LaTeX.

Emacs Org Mode is a powerful and versatile tool for information management, planning, and writing. Its main features include:

  1. Note Organization:
    • Allows creating and managing structured notes with a tree-like system, facilitating navigation and hierarchy of information.
  2. Task Management:
    • Includes features for time tracking and task management (todo), supporting custom states, deadlines, and priorities.
  3. Planning:
    • Offers tools for project and activity planning, integrating calendars and deadlines with the ability to generate detailed reports.
  4. Writing and Formatting:
    • Enables writing documents in a simple and intuitive way, with Markdown-like formatting and support for exporting to various formats (HTML, LaTeX, PDF).
  5. Code Integration:
    • Supports inserting and executing code in various languages (org-babel), allowing the creation of interactive and dynamic documents.
  6. Customization and Extensibility:
    • As part of Emacs, Org Mode is highly customizable and extendable through packages and personalized configurations.
  7. Collaboration:
    • Supports synchronization with services like Git and collaboration tools such as org-protocol for effective information sharing.

In summary, Org Mode is an ideal tool for those seeking an integrated way to manage notes, projects, and tasks, all within a flexible and powerful writing environment.

πŸ“„ Promise: Your life in plain text

I love simple and concise things, writing documents is one of the top common computer related tasks, billions of people writing some kind of document using PC, tablet, smartphone. In the last 50 years, technologies for manipulating text have evolved enormously, reaching high degrees of complexity, culminating in the word processor that saves my texts in a binary file (read software program) that becomes retro-incompatible every few years. Certainly, in my lifetime, I will bring text back to being textβ€”something that represents a universal interface for exchanging data, information, and ideas. Is here that Org-mode enter my life. My TODO lists, my personal static webpages, my drafts and notes, my recipes, all this text objects are managed in org-mode. For manipulating org-mode documents I use Emacs, but is possible to use VScode too. In the last years I've developed several .org templates useful for different kind of works, in this page I would demonstrate one of the simplest.

πŸ”΄ Organize the job

activity.png

The repo for this example

Repo on my personal Gitea

repo.png

Figure 1: org-mode template

πŸ“„ A bounch of simple text files

A simple HTML responsive page is created by:

  • template.org Main document, your org-mode document
  • template.css CSS classes for HTML export, write once, reuse everywhere
  • template.js JS basic boilerplate for HTML export, write once, reuse everywhere

template.org

This template file is crafted primairly for HTML output, in order to write a simple and clean article, or some tech documentation. An acceptable document quality is assured also exporting to PDF or ODT.

#+TITLE: 🦄 Esempio di Documento Org-mode
#+AUTHOR: Il Tuo Nome
#+DATE: [2024-10-09]
#+OPTIONS: toc:t num:t
#+LANGUAGE: it
# Rimuovi h2 'Indice' dalla tok
#+HTML_HEAD: <style>#table-of-contents h2 { display: none; }</style>
# Include CSS
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="template.css">
# Include JavaScript
#+HTML_HEAD: <script type="text/javascript" src="template.js"></script>
# Crea pulsante hamburger (need template.js)
#+HTML: <button id="toc-toggle">☰ Menu</button>

* Introduzione
Org-mode è uno strumento versatile che ti permette di creare documenti organizzati, tenere traccia di progetti, scrivere codice eseguibile e molto altro. Questo documento mostra alcune delle sue funzionalità principali.

** Caratteristiche principali
  - Facile gestione di *task* e *progetti*.
  - Supporto per collegamenti e immagini.
  - Esportazione in vari formati come HTML, LaTeX, PDF, Markdown.
  - Esecuzione di codice in vari linguaggi.

* Liste
** Liste ordinate
  1. Primo elemento
  2. Secondo elemento
  3. Terzo elemento

** Liste non ordinate
  - Punto 1
  - Punto 2
    - Sottopunto 2.1
    - Sottopunto 2.2

* Tabelle
Org-mode supporta anche la creazione di tabelle formattate.

| Prodotto   | Prezzo | Quantità |
|------------|--------|----------|
| Penne      | 1.50€  | 10       |
| Quaderni   | 3.00€  | 5        |
| Matite     | 0.80€  | 20       |
| Totale     | 5.30€  | 35       |

* Collegamenti
Ecco un esempio di un collegamento a un altro file o sezione:
  - Vai alla sezione BibliotecaCasalinga

* Blocco di codice sorgente
Org-mode ti permette di scrivere e eseguire codice in vari linguaggi. Ecco un esempio in Python:

#+BEGIN_SRC python :results output :exports both
def somma(a, b):
    return a + b

print(somma(5, 7))
\\#+END_SRC

* Note a piè di pagina
Org-mode gestisce anche le note a piè di pagina facilmente.[fn:1]

* Esportazione in LaTeX
Se vuoi includere equazioni matematiche, puoi usare la sintassi LaTeX.

Esempio di equazione in linea: $E = mc^2$

Esempio di equazione bloccata:

\[
a^2 + b^2 = c^2
\]

* Immagini
Puoi includere immagini nel documento:

[[file:immagine.png]]

* Task Management
Org-mode ti permette di gestire *TODO* e *PROGRESS*:

** TODO Scrivere un articolo
DEADLINE: <2024-10-15>

** PROGRESS Studiare Org-mode
  - [X] Capire le basi
  - [ ] Approfondire le opzioni avanzate

* Conclusione
Org-mode è uno strumento estremamente potente per l'organizzazione delle informazioni e la produttività. Esplora ulteriormente le sue funzionalità per adattarlo alle tue esigenze!

*Note*
[fn:1] Questa è una nota a piè di pagina.

template.css

@import url("roboto/roboto.css");
body {
    font-family: "Roboto-Regular", sans-serif;
    background-color: #f4f4f9;
    color: #333;
    margin: 0;
    padding: 0;
    display: flex;
}

#table-of-contents {
    width: 250px;
    height: 100vh;
    overflow-y: auto;
    position: fixed;
    left: 0;
    top: 0;
    background-color: #ffffff;
    padding: 20px;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
    transition: transform 0.3s ease-in-out;
}

#postamble {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 270px;
    background-color: #ffffff;
    padding: 10px;
    box-shadow: 0 -2px 5px rgba(0,0,0,0.1);
    font-size: 0.9em;
    z-index: 1000;
}

#content {
    margin-left: 370px;
    padding: 20px;
    flex-grow: 1;
}

blockquote{
    width: 100%; 
    max-width: 1400px; 
    height: auto;
    border: 1px solid #ddd;
    padding: 10px;
    box-sizing: border-box;    
}

blockquote img {
    width: 100%; 
    height: auto; 
    display: block; 
}


h1 {
    color: #1E569F;
    font-size: 2.5em;
    text-align: center;
}

h2 {
    color: #2883FA;
    font-size: 2em;
    border-bottom: 2px solid #2a7ae2;
}

h3 {
    color: #388964;
}

ul {
    list-style-type: square;
    margin-left: 20px;
}

li {
    margin-bottom: 10px;
    padding: 5px;
    border-radius: 5px; 
    transition: background-color 0.3s ease, color 0.3s ease;
}

li:hover {
    background-color: #e0f0ff;
    color: #2a7ae2; 
}

li::marker {
    color: #2883FA; 
    font-size: 1.2em;  
}

tr {
    margin-bottom: 10px;
    padding: 5px;
    border-radius: 5px; 
    transition: background-color 0.3s ease, color 0.3s ease; 
}

tr:hover {
    background-color: #e0f0ff; 
    color: #2a7ae2; 
}

.checkbox {
    color: #e60000;
}

.done {
    color: green;
    text-decoration: line-through;
}

#text-table-of-contents ul {
    padding-left: 20px;
}

#text-table-of-contents ul li {
    margin-bottom: 5px;
}

#text-table-of-contents ul li a {
    text-decoration: none;
    color: #333;
}

#text-table-of-contents ul li a:hover {
    color: #2a7ae2;
}

#toc-toggle {
    position: fixed;  
    top: 10px;        
    left: 10px;       
    z-index: 2000;
    background-color: #2a7ae2;
    color: white;
    border: none;
    padding: 5px;
    cursor: pointer;
    transition: none;
    display: none;
}

/*------------- mobile -----------------------------------------------*/
@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    #toc-toggle {
        display: block;
    }

    #table-of-contents {
        width: 70%;
        max-width: 200px;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        z-index: 1500;
    }

    #table-of-contents.active {
        transform: translateX(0);
    }

    #content.shift-right {
        transform: translateX(70%);
        transition: transform 0.3s ease-in-out;
    }

    #content {
        margin-left: 0;
        padding-top: 60px;
        width: 90%;
    }

    #postamble {
        transform: translateX(-100%);
        left: 0;
    }

    #toc-toggle {
        display: block;
    }
}

template.js

// simple management of responsive toc
document.addEventListener("DOMContentLoaded", function() {
    var tocToggle = document.getElementById("toc-toggle")
    var tableOfContents = document.getElementById("table-of-contents");
    tocToggle.addEventListener("click", function() {
        tableOfContents.classList.toggle("active");
    });
});

πŸ› οΈ Export the document

The C-c C-e key binding open emacs org-mode export menu, as you can see we have multiple choices.

emacs_export.png

Figure 2: org-mode export menu

Export to HTML

template.org produce template.html that include CSS and JS exposed above

org2html.png

Figure 3: org-mode to HTML

org2html_mobile.png

Figure 4: org-mode to HTML (mobile)

Export to PDF

template.org produce template.pdf a standard org-mode PDF

org2pdf.png

Figure 5: org-mode to PDF

Export to ODT

template.org produce template.odt a word processor suited file in a open standard format ODT

org2odt.png

Figure 6: org-mode to ODT

πŸ“¦ Optimize all in one HTML file

Whith the setup illustrated above when we export to HTML we need CSS and JS files along the exported html. One webpage template.html need template.css and template.js. If the document must be uploaded and served via http, in many circumstancies is safe to put all in a unique HTML file.

Put the script below alongside the .html, .css, .js files and run python3 html_optimizer.py this will generate optimized_template.html thats contain CSS classes and JS code into itself, more simplicity for deployment.

html_optimizer.py

import os

def inline_assets(html_file, css_file, js_file):
    # Leggi il contenuto dell'HTML
    with open(html_file, 'r', encoding='utf-8') as file:
        html_content = file.read()

    # Leggi il contenuto del CSS
    with open(css_file, 'r', encoding='utf-8') as file:
        css_content = file.read()

    # Leggi il contenuto del JavaScript
    with open(js_file, 'r', encoding='utf-8') as file:
        js_content = file.read()

    # Inline del CSS: Sostituisci il link del CSS con il contenuto in stile
    html_content = html_content.replace(
        f'<link rel="stylesheet" type="text/css" href="{css_file}">',
        f'<style>\n{css_content}\n</style>'
    )

    # Inline del JS: Sostituisci il link del JS con il contenuto in uno script
    html_content = html_content.replace(
        f'<script type="text/javascript" src="{js_file}"></script>',
        f'<script type="text/javascript">\n{js_content}\n</script>'
    )

    # Salva il nuovo file HTML in un altro file
    output_file = f'optimized_{os.path.basename(html_file)}'
    with open(output_file, 'w', encoding='utf-8') as file:
        file.write(html_content)

    print(f"File HTML ottimizzato generato: {output_file}")

# Specifica i percorsi dei file
html_file = 'template.html'  # Il file HTML
css_file = 'template.css'  # Il file CSS
js_file = 'template.js'    # Il file JS

# Esegui l'inlining
inline_assets(html_file, css_file, js_file)

Author: Flavio Ferretti

Created: 2024-10-16 Wed 15:54

Validate