branquito
branquito

Reputation: 4044

jekyll static site generator with sqlite3

I know Jekyll is all about "don't use database, use static files instead", but if I would like to implement rating on my static site, just to be able to store how many stars each of my pupils rated some composition, and then show an average, and with 'sqlite' being a file-based database, would it be possible to write/read from that sqlite file, using some javascript api?

Upvotes: 1

Views: 1901

Answers (3)

Yes it is possible to add database capabilities to your Jekyll generated static sites. In my case I am making use of firebase. Firebase by Google provides us many capabilities like storage, database , hosting and also access to serverless architecture using functions.

So coming to do point, all you need to do is register with http://firebase.google.com Then create an app and then in your JavaScript add following code in head tag

<script src="https://www.gstatic.com/firebasejs/5.9.0/firebase.js"></script>
<script>
  // Initialize Firebase
  // TODO: Replace with your project's customized code snippet
  var config = {
    apiKey: "<API_KEY>",
    authDomain: "<PROJECT_ID>.firebaseapp.com",
    databaseURL: "https://<DATABASE_NAME>.firebaseio.com",
    projectId: "<PROJECT_ID>",
    storageBucket: "<BUCKET>.appspot.com",
    messagingSenderId: "<SENDER_ID>",
  };
  firebase.initializeApp(config);

var timestamp = new Date().valueOf();
            var obj = {};
            obj[timestamp] = "1";

            firebase.database().ref('/').update(obj)
</script>

For more details, You can visit my blog on this topic

https://xyzcoder.github.io/firebase/2019/03/17/firebase-real-time-database.html

Note: we can also implement security restrictions on who can read and write data to our json store

Thanks, Pavan

Upvotes: 0

David Jacquel
David Jacquel

Reputation: 52809

You can give a try to firebase or cloudbase.io they both offers free plans and javascript API.

Firebase has a very good documentation.

Upvotes: 4

aug
aug

Reputation: 11714

You should not use JavaScript to access your database -- it will make it vulnerable because your information is exposed to the client. It's definitely possible but highly not recommended.

However, there are ways to use Jekyll in conjunction with more appropriate languages like PHP which may or may not be what you are looking for. I am not entirely familiar with how Jekyll works but if I understand correctly, if it's simply generating static files you may be able to make certain parts of your site generated by Jekyll but then other parts run on PHP to make those SQL calls.

It would definitely be a little hacky though so I would really assess how important it is you want to use Jekyll. Please keep in mind Jekyll is made for a very specific purpose -- transforming plain text into static sites so this probably is not the right tool for you.

Upvotes: 1

Related Questions