Presentazioni

Presentazione in html in un post

Introduzione #

Quarto consente di produrre e inserire presentazioni in un post, una caratteristica magari di uso non frequente, ma utile. Da quando sono tornato a Hugo questa possibilità, apparentemente la ho persa, vedi Gioco con quarto. Ci sono temi in cui i post sono solo presentazioni, ma sono troppo restrittivi per i miei scopi. Così ho provato a curiosare per avere quella potenziale utile caratteristica.

present in Go #

Mi è subito venuto in mente che poteva esserci qualcosa con Go, il linguaggio con cui è scritto Hugo e infatti esiste present

Package present implements parsing and rendering of present files, which can be slide presentations as in golang.org/x/tools/cmd/present or articles as in golang.org/x/blog (the Go blog).

Il pacchetto present legge un file con estensione .slide e ne produce un’altro con estensione html. Purtroppo non esiste un modo veloce per sfruttarlo nel blog, di conseguenza la soluzione è stata scartata.

La vecchia maniera #

Alla fine dei conti una presentazione è un file di testo con del markup e allora tanto vale inserirlo direttamente nel post dove serve in questo modo1:

<div class="presentation">

  <div class="slide active">
    <h1>Slide 1: Introduction to Climate Change</h1>
    <p>Climate change refers to significant changes in global
    temperatures and weather patterns over time.
    While climate change is a natural phenomenon, scientific evidence
    shows that human activities are currently driving an unprecedented 
    rate of change.</p>

  </div>

  <div class="slide">
    <h1>Slide 2: Causes of Climate Change</h1>
    <ul>
      <li><strong>Greenhouse Gas Emissions:</strong> Carbon dioxide 
      (CO2) from burning fossil fuels.</li>
      <li><strong>Deforestation:</strong> Reduces the number of trees
      that can absorb CO2.</li>
      <li><strong>Industrial Processes:</strong> Emissions from
      manufacturing and chemical production.</li>
    </ul>
  </div>

  <div class="slide">
    <h1>Slide 3: Effects of Climate Change</h1>
    <ul>
      <li><strong>Rising Sea Levels:</strong> Melting ice caps and 
      glaciers contribute to higher ocean levels.</li>
      <li><strong>Extreme Weather Events:</strong> Increased frequency
      of hurricanes, droughts, and floods.</li>
      <li><strong>Impact on Biodiversity:</strong> Species extinction
      and habitat loss.</li>
    </ul>
  </div>

  <div class="slide">
    <h1>Slide 4: Solutions to Combat Climate Change</h1>
    <ul>
      <li><strong>Renewable Energy:</strong> Transitioning to solar,
      wind, and hydroelectric power.</li>
      <li><strong>Energy Efficiency:</strong> Improving energy use
      in buildings and transportation.</li>
      <li><strong>Reforestation:</strong> Planting trees to absorb
      CO2 and restore ecosystems.</li>
    </ul>
  </div>

  <div class="slide">
    <h1>Slide 5: Conclusion</h1>
    <p>Addressing climate change requires collective action from 
    individuals, businesses, and governments. By adopting sustainable
    practices and supporting policies that reduce emissions,
    we can work towards a healthier planet for future generations.</p>
  </div>

  <div class="slide">
    <h1>Slide 6: Questions?</h1>
    <p>Feel free to ask any questions or share your thoughts 
    on how we can combat climate change together!</p>
  </div>

</div>

<button class="prev" onclick="changeSlide(-1)">&#10094; Prev</button>
<button class="next" onclick="changeSlide(1)">Next &#10095;</button>


<style>
.presentation {
  position: relative;
  width: 100%;
  max-width: 800px; /* Adjust as needed */
  margin: auto;
  overflow: hidden;
}

.slide {
  display: none; /* Hide all slides by default */
  padding: 20px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  background-color: #fff; /* Background color for slides */
}

.slide.active {
  display: block; /* Show the active slide */
}

button {
  margin: 10px;
  padding: 10px 20px;
  cursor: pointer;
}
</style>

<script>
let currentSlide = 0;
const slides = document.querySelectorAll('.slide');

function showSlide(index) {
  // Ensure the index is within bounds
  if (index >= slides.length) {
    currentSlide = 0; // Loop back to the first slide
  } else if (index < 0) {
    currentSlide = slides.length - 1; // Loop to the last slide
  } else {
    currentSlide = index; // Set the current slide
  }

  // Hide all slides and show the current one
  slides.forEach((slide, i) => {
    slide.classList.remove('active');
    if (i === currentSlide) {
      slide.classList.add('active');
    }
  });
}

// Function to change slides
function changeSlide(direction) {
  showSlide(currentSlide + direction);
}

// Show the first slide initially
showSlide(currentSlide);
</script>

Il codice viene interpretato da Hugo così

Slide 1: Introduction to Climate Change

Climate change refers to significant changes in global temperatures and weather patterns over time. While climate change is a natural phenomenon, scientific evidence shows that human activities are currently driving an unprecedented rate of change.

Slide 2: Causes of Climate Change

  • Greenhouse Gas Emissions: Carbon dioxide (CO2) from burning fossil fuels.
  • Deforestation: Reduces the number of trees that can absorb CO2.
  • Industrial Processes: Emissions from manufacturing and chemical production.

Slide 3: Effects of Climate Change

  • Rising Sea Levels: Melting ice caps and glaciers contribute to higher ocean levels.
  • Extreme Weather Events: Increased frequency of hurricanes, droughts, and floods.
  • Impact on Biodiversity: Species extinction and habitat loss.

Slide 4: Solutions to Combat Climate Change

  • Renewable Energy: Transitioning to solar, wind, and hydroelectric power.
  • Energy Efficiency: Improving energy use in buildings and transportation.
  • Reforestation: Planting trees to absorb CO2 and restore ecosystems.

Slide 5: Conclusion

Addressing climate change requires collective action from individuals, businesses, and governments. By adopting sustainable practices and supporting policies that reduce emissions, we can work towards a healthier planet for future generations.

Slide 6: Questions?

Feel free to ask any questions or share your thoughts on how we can combat climate change together!


Mi sembra una soluzione accettabile, ma se, per esempio, qualcuno avesse molte presentazioni e ne volesse fare un portfolio sul proprio blog? A questo cercherò di rispondere in un altro post, stay tuned, come direbbe un geek.


  1. il testo delle slide lo ho rubato da qualche parte che non ricordo. ↩︎