1

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?

branquito
  • 3,864
  • 5
  • 35
  • 60

3 Answers3

4

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

Firebase has a very good documentation.

David Jacquel
  • 51,670
  • 6
  • 121
  • 147
  • Hey, this is very good. So using firebase free(hacker) plan hosting, I get easy deploying, static site - storage posibilities etc..? Great. – branquito Nov 21 '14 at 11:23
  • Just cannot thank you enough, David.. for pointing me to Firebase. It's excellent to combine with static-generated files like Jekyll ones, when you need anything like weather info on page, or rating stuff in my case :) Cheers! – branquito Nov 30 '14 at 15:24
1

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.

Community
  • 1
  • 1
aug
  • 11,138
  • 9
  • 72
  • 93
  • I cannot have PHP interpreter on server which I am using to host my jekyll site, so I cannot use those `raw` tags. And I suppose also, ajax request to some other domain would not be possible, using php script there instead? – branquito Nov 21 '14 at 11:08
  • You will run into cross origin issues when making ajax calls to other domains. You might want to add to your question what your server is running and will allow. – aug Nov 21 '14 at 11:12
  • It won't allow for anything more than simple serving. I will stick with `all-static` version, no rating, it is not that important for me, I was just being curious. Thanks for your pacience. – branquito Nov 21 '14 at 11:15
  • Take a look at David's answer - firebase might be what you're looking for. I just looked up some places that use them together. Keep in mind everything is public to the user though. – aug Nov 21 '14 at 11:22
  • That's not an issue, I want it to be all public anyway. Although it seems that firebase is also giving `simple user authentication`.. ;) – branquito Nov 21 '14 at 11:24
0

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