DEV Community

Discussion on: Static Portfolio with dynamic content

Collapse
 
niklasfyi profile image
Niklas Resch • Edited

First of all thanks a lot for the long answer and sorry for my late reply...

Real-time would be really nice but I absolutely don't want to have my keys in the front-end. A script or service in the backend would be great.

I already tried static site generators like Jekyll, Hugo, Pelican and Nikola. They are really great and I really like to use them.

A job that checks my Mastodon-feed or Blog and triggers a rebuild of Jekyll, Hugo or whatever would be pretty good.

Your idea with a JSON or YAML file sound interesting. I haven't thought about that.

So my problem is not the static site. It's more like how do I rebuild it after a blog post or a toot and what would be the most efficient way.

Thanks!

Collapse
 
rpalo profile image
Ryan Palo

Cool! And now I totally get what you are wanting. So now we have a couple of options. You could go the pure python route and use the built-in schedule module. I’ve got a project called Fanbot that tweets a compliment at my brother every day that is similar to what you want to do. Or you could go pure Bash and do it through an hourly/daily cron job.

Either way, you’ll need a server to run this for you (or a serverless function). Options are an old computer you’ve got laying around, buy a raspberry pi for pretty cheap, or maybe a $5/month Digital Ocean box. AWS would also work, although I’ve found it to be a lot less user friendly. Netlify has functions that might actually handle the data fetching and optional rebuild for you. Not sure.

The recurring job would check each feed, and, if there had been any updates, download them, rebuild your site, and push the changes to your repo.

I’m happy to help you out with whatever combination you want to try. Do any of these ideas sound good? :)

Thread Thread
 
rpalo profile image
Ryan Palo

Sorry I just thought of another idea. You might be able to scrape Twitter from the front end, bypassing the api and avoiding the rebuild step at all, but not sure.

Thread Thread
 
niklasfyi profile image
Niklas Resch

I will have a look at your Fanbot project.

I just got it working with Hugo and gohugo.io/templates/data-templates.... You just have to disable caching and rebuild Hugo everytime.

Now I just need to use a cronjob or some other script to trigger the rebuild.

How do you want to do it with Twitter and the front end?

Thread Thread
 
rpalo profile image
Ryan Palo

Something similar to this? Essentially fetch your Mastodon feed from the client side and dynamically show your tweets?

Personally I like the server side option better, but that’s just me. It’s nice because it gives you a handy backup of all your data in one place too!

Thread Thread
 
niklasfyi profile image
Niklas Resch

This will just print the content of my last public toot from Mastodon.

<ul>
  {{ $urlPre := "https://chaos.social" }}
  {{ $gistJ := getJSON $urlPre "/api/v1/accounts/166987/statuses?limit=1" }}
    {{ .content | plainify }}
</ul>

I don't need any backup. I just want to show the last toot and link to it. So I think that would be simple enough.

When the site is complete I will check how long the hugo build will run on my uberspace.de host and then I can think about the frequency of building. Maybe every 30 min.

Thread Thread
 
rpalo profile image
Ryan Palo

The nice thing about backup is you can check to see if there have been any tweets, and only build if that is the case. If you’re averse to deploying super frequently, maybe that’s a good idea. Otherwise, what you have sounds great! 😁