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

Failure

This is a chapter from my latest book called (G)rains (o)f san(d)s. Learn more about the book here . Thank you God for failure. Thank you for the good days and the bad days. Thank you for the journey. There are no failures, only lessons learnt. Better to try and fail than fail to try. For this chapter I made a bunch of notes and pieced them together. If mosaic was a style of writing, this would be it for me. Weirdly enough I am not afraid of failure as much as I am afraid of success. I want to live an ordinary and simple life. Much of what society deems as success is really the rat race. I guess I do not have a problem with success but the mainstream definitions of success. What does failure teach us? Failure teaches us to never give up because success can be right around the corner. Define your own definition of success. Enjoy the journey. Focus on learning. Focus on gaining experience. Focus on becoming wise. Today I learnt how a pearl is formed. A pearl forms when an oyster responds...

Wisdom

This is a chapter from my latest book called (G)rains (o)f san(d)s. Learn more about the book here . Thank you God for wisdom. Age brings wisdom. At least it should. Everyday we are learning. Everyday we are growing. What is the wisest thing ever said? I think one of the wisest things ever said is something my grandfather told my mother which is, "Dont make nothing a problem." Let me digest what was meant by this. Life happens. Fix what we can. Let go of what we cannot fix. Fix what is within our control. Get help when needed. Let go and let God. There are no problems only solutions waiting to be found and lessons waiting to be learnt. Every problem has a solution. Do not look at the problem, look at the solution. Do not see the problem, see the solution. What defines the situation is not the problem but the solution. We get to choose how we react to what we face in life. They say that laughter is the best medicine. If we do not laugh we will cry. So sometimes wisdom comes wi...

Faith

This is a chapter from my latest book called (G)rains (o)f san(d)s. Learn more about the book here . Thank you God for faith. We say we want to meet God but we already do in some ways. We meet God in his creation. We meet God every time we meet someone. We meet God every time we meet the animals. We meet God every time we meet nature. God is all around. Faith is when we can see this. This is God's world. We are God's work. We are testimony of his greatness. Everyday that goes by I think about God. Everyday I thank God for his mercy. I take my problems to God. I pray to God. God is at the center of my life. Nothing happens without the will of God and therefore I would be wise to submit to the will of God. God is in the everyday moments. God loves when we love. What is the simplest definition of faith? I think it is found in the phrase, let go and let God. I asked my friend the same question. My friend says that at its simplest, faith is trust in what you cannot see or prove. But...