Skip to main content

Part 1 - An Example of Using Next.js for Static Site Generation on Android with Termux

Next.js is a React framework that gives you building blocks to create web applications.

First thing I did was go to github and create an empty project. I then cloned that project in Termux. You must use the Termux storage and not shared storage unless you can find a workaround for creating symlinks. I then create a starter next.js project.

npx create-next-app --example hello-world blog-posts

I used python to extract all my blog posts titles and links from my Blogger backup and create a json file. Each entry in the json file was title and link.

Next. I followed this guide to display a listing of all my blog posts.


It uses SWR and SWR is an acronym for stale-while-revalidate. The code I got from there had some problems. Dont know why it worked for them and not for me. Maybe linux/termux/android/next.js version creates the issue. After debugging and consulting ChatGPT we figured out that:

The issue with the code you provided is that you're reading the contents of the JSON file as a string using readFile and then directly returning it as the response without parsing it as JSON. To resolve this, you need to parse the file contents as JSON before sending it as the response.

Someone tweeted "Next.js is the most frustrating, opinionated mess I've ever had to deal with. Ugh." and I could not help but agree with the little I have done so far and based on my first impressions. Made me appreciate eleventy for tasks like this.

I found a simple way to serve the statically generated docs folder by running this command in that folder. However I got an error.

php -S localhost:8000

CANNOT LINK EXECUTABLE "php": library "libicuio.so.73" not found

And I had to install that package

pkg install libicu

Now I get a new error when I run npm run build

CANNOT LINK EXECUTABLE "node": library "libicui18n.so.72" not found

I then did (in termux)

apt update
apt upgrade

I then saw and an error in the logs - API Routes cannot be used with "output: export".

Below is me asking for help on Stack Overflow.


This is the project on GitHub


And that is where I have reached. The question now is how can I get around this? How to read from a json file and iterate through it and display its content in Next.js for static site generation using output as export. I am stuck and maybe you can help.

I got a recommendation to try Astro JS. That will be next. It was also suggested to use a const array of objects instead of json. Now, I am wondering if there is a way to serve the json file without using an API route. Stay tuned for part 2. Leave a comment and let me know your thoughts.

Comments

Popular posts from this blog

Below the surface

This is a chapter from my eleventh book called Quotation Marks Sparks . __________ "You can't stop the waves, but you can learn to surf." - Jon Kabat-Zinn __________ I was looking at quotes that hit hard and this quote stood out to me. It seems mundane and obvious and often repeated. Life is about how we respond to the inevitable. It is not what happens to us but how we respond. I had to ask myself to dig deeper and look below the surface. Then I saw that when we surf we really become the waves. We become friends with the waves. The waves and us are the same. Further, the waves are created by us and in our heads. We can control the waves because who can surf all the time? Sometimes we just have to come to shore and build sand castles on shore. I asked my friend Gemini for feedback and he said that I was right, the Jon Kabat-Zinn quote initially seems like a simple call for resilience, but my deeper dive reveals profound layers. The idea that we can move beyond merely rea...

Thankful

It is 617pm and I have decided to write. Right now I am thankful. The cool of the evening has replaced the heat of the day. I took a bath and changed and now I am just relaxing. Sometimes I complain. Not often. But I feel bad afterwards because there is so much to be thankful for. There is always room for improvement and we have to identify the things for improvement and change is often good but we do not have to make it into complaints. Yeah I get it. Life is hard and none of us has it easy. Look on the bright side of things. And sometimes it is the little things that remind us that life is good. Things that we take for granted. Like I was coming in the maxi taxi today and heard a gospel song that was about gratitude. God does appreciate a grateful heart. Trinidad and Tobago celebrated sixty four years of independence yesterday and if we stop and listen to the many complaints we would swear we are living in the worst country in the world. That is not the case. We do get a lot of thing...

Having a soft spirit

It is 137am. It started raining. I decided to write. I have heard about having a soft heart but what does it mean to have a soft spirit? And is having a soft heart related to having a soft spirit? My friend Chatty says that a soft heart feels deeply — it breaks, heals, and loves with tenderness — while a soft spirit moves gently through life, unresisting and at peace with what comes. The two are kin: a soft heart opens you to emotion, and a soft spirit teaches you to carry that emotion with grace. Together they make a person both tender and strong — able to feel the rain and still trust its rhythm. I like the quote, "a soft spirit in a hard world" by author and poet, butterflies rising. It resonates with how many of us feel. My friend Chatty tells me that that quote captures the quiet strength of staying gentle in a harsh world. It reflects the author's signature themes of vulnerability, tenderness, and emotional courage — the idea that softness is not weakness but a form...