static blog

Come creare un Blog con Hugo e Google Docs come BackEnd

Ricerca Eccoci qua finalmente! In questi giorni ho sentito la necessità di creare questo blog che state proprio visitando! Mentre navigavo on line, sono venuto a conoscenza degli static site generator; ho sempre saputo della loro esistenza ma non avevo mai dedicato loro molta importanza. Tuttavia, navigando più a fondo, sono stato attratto da Hugo, uno fra i tanti nuovi motori per generare website statici. No Wordpres Partivo dall’esigenza di avere qualcosa di statico in quanto non dispongo di un server dove installare Wordpress o altri CMS e, per un piccolo blog personale, non credo sia necessario e oltretutto è troppo costoso. Infine, volevo che il blog fosse efficiente e scalabile e cross platform. DRY La prima cosa a cui ho pensato da programmatore è stata: quante operazioni dovrò fare per eseguire un deploy senza un CMS? come farò a portare i miei nuovi contenuti online? Sono anche un’amante di Google Docs e mi piace scrivere ed avere tutto in un unico posto. Allora mi sono chiesto: come posso unire Hugo e Google Docs senza dover girare mille manovelle? Innanzitutto, ho studiato la struttura dei contenuti MarkDown e mi sono messo alla ricerca di qualcosa che mi desse la possibilità di convertire i Documenti Google in MarkDown. La cosa più utile che ho trovato sul web è stato questo Google script mangini/gdocs2md: Convert a Google Drive Document to the Markdown format, suitable for publishing. a cui faccio i miei più sentiti ringraziamenti. Nonostante la comprovata efficacia del suddetto script, avevo bisogno di qualcosa in più rispetto al ricevere la conversione di un articolo via mail. Di conseguenza, per avere qualcosa di più automatizzato, ho modificato un pò lo script e creato il link che vedi sotto: Link allo script su github Lo script converte tutti i documenti elencati in un foglio Google, organizza in cartelle per categorie, estrae immagini da articoli, aggiunge l’intestazione del MarkDown, i tags ed infine crea un file zip contenente tutti i contenuti. Ho deciso di impostare lo zip con visibilità pubblica quindi scaricabile, pronto per il deploy. Ho successivamente creato una sorta di database utilizzando uno sheet di Google come se fosse una tabella con la seguente struttura: ToDeploy Title Summary SummaryImage Category Data tag1 tag2 tag3 tag4 tag5 Language 1 Come Inviare File PDF e articoli web al Kindle da Android 0 Kindle 2020-05-09 kindle pdf articolo web send to kindle android it In questo modo ho la possibilità di fare il deploy di tutto o di aggiornare solo ciò che ho modificato utilizzando il primo campo ToDeploy. Successivamente, ho creato un altro google script che riceve in ingresso l’id della cartella su cui è presente lo zip precedentemente creato e restituisce l’url pubblico da cui effettuare il download dello zip con i contenuti. function doGet(e) { params = JSON.parse(JSON.stringify(e)); var docid = params.parameters.docid; if(docid==null || docid=="") return; var parentFolder=DriveApp.getFolderById(docid); if(parentFolder==null) return; var url = parentFolder.getFilesByName("BlogProd.zip").next().getDownloadUrl(); return ContentService.createTextOutput(url); } Infine ho messo tutte insieme all’interno del seguente script linux sh in modo da poter automatizzare build e il deploy: #!/bin/bash #ln -s /home/yourname/works/luciosoftsite/blog/ ~/luciosoftsite #ln -s /home/yourname/works/luciosoftsite/blog/content/ ~/luciosoftblogcontent #requirements wget|unzip|hugo folderid="your google doc folder id” yourscriptid=”your google script id” cd ~/luciosoftblogcontent; retriveurl="https://script.google.com/macros/s/$scriptid/exec?folderid=$folderid”; downlodUrl=$(wget $retriveurl -q -O -); fileName="download.zip"; wget -c $downlodUrl -O $fileName; unzip -o $fileName; rm -f $fileName; cd ~/luciosoftblog; #hugo serve -D HUGO_ENV="production" hugo --config config.yaml firebase deploy Lo script è molto semplice, non fa altro che richiamare lo script google per recuperare l’url di download. Una volta recuperato l’url, a questo punto lo script effettua il download dello zip, estrae i contenuti all’interno del folder dei contenuti di Hugo, esegue il comando per creare Build, ed infine richiama firebase per effettuare il deploy. E anche oggi la magia è avvenuta. Sì, probabilmente avrei potuto seguire mille altre strade, anche più sicure e più efficienti ma questo è un inizio, il mio obiettivo era più grande. Vorrei trasformare lo script linux in un container docker e lo script google in un’applicazione dinamica con login google. Ma questa è un’altra storia che, se avrà seguito, vedrete prossimamente in un altro link all’interno del mio blog :) Poject ghithub link

How to create a Blog with Hugo e Google Docs as BackEnd

Research In these days I have felt the need to create the blog you are reading. While surfing the web, I became aware of the static site generators, I have always known what they are and that they have always existed but I had never given them much attention. Though, while surfing deeper, I was attracted by Hugo, one of the many new engines to generate static websites. No WordPress I needed to have something static for I don’t have a server where I can install Wordpress or other CMS and, for a small personal blog, I don’t think it’s necessary and it is also too expensive. Finally I wanted the blog to be efficient and scalable and cross platform. DRY The first thing I thought about as a programmer was: how many operations do I need to do to deploy without a CMS? how will I bring my new content online? I am also a Google Docs lover and I like writing and having everything in one place. So I asked to myself: how do I combine Hugo and Google Docs without having to turn a thousand cranks? I studied the structure of MarkDown content and I started looking for something to convert Google Docs to MarkDown. The only useful thing I found on the web was this Googlescript mangini/ gdocs2md: Convert to Google Drive Document to the Markdown format, suitable for publishing. to whom I offer my heartfelt thanks. Although this script is very effective, I needed something more than receiving the conversion of an article by email. To have something more automated, I modified the script a bit and created the link script as follows: Link to my github repos The script converts all the documents listed in a Google sheet, organizes into folders by categories, extracts images from articles, adds the MarkDown header, tags and finally creates a zip file containing all the contents. I decided to make the zip public and therefore downloadable, ready for deployment. I then created a sort of database using a Google sheet as a table with this struct: ToDeploy Title Summary SummaryImage Category Date tag1 tag2 tag3 Tag4 Tag5 Language 1 Send As PDF files and web articles to the Kindle from Android 0 Kindle 09/05/2020 kindle pdf web article send to kindle android it In this way I have the possibility to deploy everything or to update only what I modified using the first field ToDeploy field. Subsequently, I created another google script that receives the id of the folder where there is the previously created zip. The script finally returns the public url from which it is possible to download the zip with the contents. function doGet (e) { params = JSON.parse (JSON.stringify (e)); var docid = params.parameters.docid; if (docid == null || docid == "") return; var parentFolder = DriveApp.getFolderById (docid); if (parentFolder == null) return; var url = parentFolder.getFilesByName ("BlogProd.zip"). next (). getDownloadUrl (); return ContentService.createTextOutput (url); } Finally I put them all together in the following script linux sh. So I can automate building and deployment: #!/bin/bash #ln -s /home/yourname/works/luciosoftsite/blog/ ~/luciosoftsite #ln -s /home/yourname/works/luciosoftsite/blog/content/ ~/luciosoftblogcontent #requirements wget|unzip|hugo folderid=”your google doc folder id” yourscriptid=”your google script id” cd ~/luciosoftblogcontent; retriveurl="https://script.google.com/macros/s/$scriptid/exec?folderid=$folderid”; downlodUrl=$(wget $retriveurl -q -O -); fileName="download.zip"; wget -c $downlodUrl -O $fileName; unzip -o $fileName; rm -f $fileName; cd ~/luciosoftblog; #hugo serve -D HUGO_ENV="production" hugo --config config.yaml firebase deploy The script is very simple, it calls the google script to retrieve the download url. Once the url is recovered, the script does the download of the zip, extracts the contents into the Hugo contents folder, executes the command to create Build, and finally calls firebase for deploy. And even today the magic has happened. Yes, I could have followed a thousand other ways, even safer and more efficient. But this is a starting point, my goal is bigger. I would like to turn the linux script into a docker container and the google script into a dynamic application with google login. But this is another story that, maybe, you will be able to see in another link at my blog :) Link al progetto ghithub