Tag: interactive

Convert a PHP/MySQL site to Jamstack and host on Github Pages

One of the first items on my sabbatical to do list last year was to convert the Camp La Jolla Military Park website to a static Jamstack site hosted at Github Pages. This post documents that process.

I originally created the site as a research tool using PHP and a MySQL database for data entry, to record, organize, and ultimately publish research about the military history of UCSD. Moving the project to Github Pages would simplify maintenance and hosting costs, but was no small task. Technically it didn’t cost me extra to host, but the domain was $20/year, which adds up. Further, maintaining a PHP/MySQL website with a custom admin tool requires a bit of overhead for security and updates. Additionally, I wanted to continue having the benefit of using template engines or some way to include files (like PHP’s require()) to save time coding the site.

There are a plethora of tools available to publish a database-driven site on a static host. They mostly can be categorized as follows (ordered by most to least dynamic data sources):

  • Move the database to a remote service like Firebase, Atlas, et al. — ⚠️ Ultimately creates vendor lock-in, potential hidden costs, and probably more maintenance issues in the future.
  • Create a static version of the database by converting MySQL to flat files (JSON, CSV, etc.), which still allows for querying using one of various tools — 🤔 This method is interesting, because it still decouples the data from the presentation and allows for potentially more options later, including a remote database. I am already using this in various forms but worry again about maintenance, or issues with the client’s ability to manipulate the data as needed.
  • Generate a static version of the site, including all its pages which contain the data formerly dynamically inserted from MySQL. — 🤔 I like this concept, and have been using it to auto-publish my class lectures and tutorials using Markdown and Grunt with Marp. Plus, there are many site generators to choose from, which I explore below.
  • Scrape the site and save pages as static files. After all, everything is static once the HTML is rendered on the frontend. — ⚠️ While fast, this requires the site be built first and would make updates difficult.

Essential Concepts

Here I outline some concepts on rendering. See SSR vs CSR vs ISR vs SSG for a more in-depth look:

  • Client-Side Rendering (CSR) (e.g. Single-Page Application (SPA)) – JS renders pages in client’s browser with empty HTML files + raw data from the server. (e.g. React, Vue, Angular)
  • Server-Side Rendering (SSR) (e.g. Fullstack) – Generates pages on server with dynamic data before delivering to client. Improves SEO and loading, decreases server performance. (e.g. EJS, PHP, or Next.js)
  • Static Site Generation (SSG) (e.g. JAMStack) – Pre-renders all pages as static HTML during build process. Fast loading times, enhanced security, and dynamic content can still be achieved via “islands”.
  • Incremental Static Regeneration (ISR) – Combines SSR and SSG to pre-render static pages during build time while periodically regenerating specific pages with updated data.
  • Edge-Side Rendering (ESR) – Rendering process is pushed to the CDN’s edge servers which handles requests and generates HTML. Requires Nitro engine.

Requirements

Requirements for most of the projects I mention above.

  1. Javascript-based
  2. The data will be static, but editable using Git
  3. The data should be searchable using a tool like chosen
  4. The site design will be simple, but I should have creative control
  5. The site will be public, and be presented mostly using the same design as the original site
  6. HTML/CSS validation + Accessibility checks
  7. Convert from Google Maps to Leaflet
  8. Host the site on Github Pages

While planning the project I also wanted to select a method I could use for other potential static (or nearly static) sites like:

  1. A new site documenting the hundreds of examples and overlapping categories of Critical Web Design and internet art I’ve been collecting for an upcoming book. Update: I built it with SvelteKit
  2. Converting tallysavestheinternet.com to a static site (currently SSR) and unlinking the extension from the server to use local data only
  3. Moving away from WordPress more generally (and its security problems) and blogging with Markdown instead, starting with this blog (NO MORE TYPING IN A WEB FORM!!)

It’s nice to learn new tools. I already have some experiences with React, Next.js, and Vue.js, but wouldn’t say I’m confident in any. I found that publishing apps using React Native is very frustrating and unreliable, and my general distrust of Facebook makes me lean towards Vue. Still, I went in with an open attitude.

Tool Comparison

A breakdown of some tools I considered. Some of the icons are clickable…

FrameworkSPASSRSSGMDThemesSearchCons
Jekyll❌❌✅✅✅?❌ Ruby
Hugo❌❌✅✅✅?❌ Go
Astro✅✅✅✅✅✅React, Vue, Svelte in dynamic islands, simple routing
Vue.js✅✅✅✅✅?✅ vuepress
Nuxt.js✅✅✅✅✅?Built on Vue
SvelteKit✅✅✅✅✅✅MD rendering not native but supported via MDX
Next.js✅✅✅✅✅✅MD rendering not native but supported via MDX

Next

My experience with Next.js SSG was painful.

  • Constantly running into subtle changes in syntax across versions
  • Adding an image is ridiculously difficult.
  • Exporting the SSG ultimately created dead links, packaged up in Next code that was hard to understand.
  • So much automation to make a static site in the end you can’t do anything unless you have the exact right code, in the right version, in the right paths.
  • Error messages are rarely helpful or pinpoint the line number causing the issue in the stack.
  • I followed so many tutorials that ultimately ended in dead-ends, incorrect versions, or that completely didn’t work.

Astro

I ended up choosing Astro for the final project, which can be seen here https://omundy.github.io/camplajolla/. While they appear to have many similarities, I found Astro soooooo much easier than Next.js. It’s fairly simple to install, even using a starter theme, and it didn’t take long torip out tailwind to add bootstrap.

New yourarthere.net website is live

After 4 months the new yourarthere.net website and member-run content management system is now live. Thanks to Braylin and Brittany Morales, Beth Lee, and Chris Cumbie for all their hard work.

The site is valid XHTML/CSS and runs on PHP/MySQL using the Codeigniter framework. All the details from our research from inception onward are archived here.

This site is based around the idea that members should have control of the content on the website. Every member has a profile where they can add images, text, tags, and events to promote their artwork or group. Members can create a new profile for every domain they host with yourarthere.nets.

Picture 6

Picture 8

Fading an LED with PWM and a Potentiometer

Using a potentiometer and PWM on an Arduino to fade an LED.

  1. /* POT to LED test -> by Owen Mundy March 11, 2010
  2. from: http://itp.nyu.edu/physcomp/Labs/AnalogIn
  3. —————————————————————*/
  4. int potPin = 0; // Analog input pin that the potentiometer is attached to
  5. int potValue = 0; // value read from the pot
  6. int led = 9; // PWM pin that the LED is on. n.b. PWM 0 is on digital pin 9
  7. void setup() {
  8. // initialize serial communications at 9600 bps:
  9. Serial.begin(9600);
  10. // declare the led pin as an output:
  11. pinMode(led, OUTPUT);
  12. }
  13. void loop() {
  14. potValue = analogRead(potPin); // read the pot value
  15. analogWrite(led, potValue/4); // PWM the LED with the pot value (divided by 4 to fit in a byte)
  16. Serial.println("hello"); // print the pot value back to the debugger pane
  17. delay(10); // wait 10 milliseconds before the next loop
  18. }

Here is the schematic for the above project.

Diagram of a potentiometer wired to an LED

Using PWM and a potentiometer to fade an LED and drive a stepper motor, powered by a Boarduino RBBB.

  1. /*
  2. Owen Mundy
  3. July 29, 2009
  4. p. 262 of Physical Computing
  5. Using BBB to run stepper motor by manually moving steppers
  6. */
  7. int pin1 = 3; // PWM
  8. int pin2 = 5; // PWM
  9. int pin3 = 6; // PWM
  10. int pin4 = 9; // PWM
  11. int ledpin = 13; // LED
  12. int led = false; // LED monitor
  13. int motor_time_lapse = 80;
  14. int potPin = 0; // Analog input pin that the potentiometer is attached to
  15. int potValue = 0; // value read from the pot
  16. int ledPotPin = 11; // PWM pin that the LED is on. n.b. PWM 0 is on digital pin 9
  17. void setup()
  18. {
  19. pinMode(pin1, OUTPUT); // sets the pin as output
  20. pinMode(pin2, OUTPUT); // sets the pin as output
  21. pinMode(pin3, OUTPUT); // sets the pin as output
  22. pinMode(pin4, OUTPUT); // sets the pin as output
  23. pinMode(ledpin, OUTPUT); // sets the pin as output
  24. // initialize serial communications at 9600 bps:
  25. Serial.begin(9600);
  26. // declare the led pin as an output:
  27. pinMode(ledPotPin, OUTPUT);
  28. }
  29. void loop()
  30. {
  31. potValue = analogRead(potPin); // read the pot value
  32. analogWrite(ledPotPin, potValue/4); // PWM the LED with the pot value (divided by 4 to fit in a byte)
  33. Serial.println(potValue);
  34. digitalWrite(pin1, HIGH); // on
  35. digitalWrite(pin2, LOW); // off
  36. digitalWrite(pin3, HIGH); // on
  37. digitalWrite(pin4, LOW); // off
  38. delay(motor_time_lapse); // wait
  39. digitalWrite(pin1, LOW); // off
  40. digitalWrite(pin2, HIGH); // on
  41. digitalWrite(pin3, HIGH); // on
  42. digitalWrite(pin4, LOW); // off
  43. delay(motor_time_lapse); // wait
  44. digitalWrite(pin1, LOW); // off
  45. digitalWrite(pin2, HIGH); // on
  46. digitalWrite(pin3, LOW); // off
  47. digitalWrite(pin4, HIGH); // on
  48. delay(motor_time_lapse); // wait
  49. digitalWrite(pin1, HIGH); // on
  50. digitalWrite(pin2, LOW); // off
  51. digitalWrite(pin3, LOW); // off
  52. digitalWrite(pin4, HIGH); // on
  53. delay(motor_time_lapse); // wait
  54. blink();
  55. }
  56. void blink()
  57. {
  58. if (led == false)
  59. {
  60. led = true;
  61. digitalWrite(ledpin, HIGH); // on
  62. }
  63. else
  64. {
  65. led = false;
  66. digitalWrite(ledpin, LOW); // on
  67. }
  68. }