Klimatbyran / klimatkollen

https://www.klimatkollen.se
MIT License
36 stars 44 forks source link

Remove old pulbic data file, and remove use of replaceLetters() #581

Closed Greenheart closed 2 weeks ago

Greenheart commented 2 weeks ago

This can be done because special characters for all names have already been replaced in the data file that is actually used (pages/data/kommuner.json).

This will first and foremost reduce confusion (I got confused why we had two kommuner.json in the project). And this will also give a slight performance improvement since we don't need to perform useless operations.

I did a global search for all the special characters that replaceLetters() is replacing and confirmed that these characters are no longer present in the project. And if we need this formatting for some reason in the future, we can search the git history, GitHub etc to get the replaceLetters() helper back.

Totally irrelevant now, but might be useful in the future:

Also, here's a script I created because I accidentally worked with the wrong dataset where strings were malformed:

import { readFile, writeFile } from 'fs/promises'
import { resolve } from 'path'

const file = await readFile(
  resolve(import.meta.dirname, 'municipalities.json'),
  { encoding: 'utf-8' },
)

export const replaceLetters = (name) => {
  const replacements = {
    'Ã¥': 'å',
    'ä': 'ä',
    'ö': 'ö',
    'Ã…': 'Å',
    'Ä': 'Ä',
    'Ö': 'Ö',
  }

  const regex = new RegExp(Object.keys(replacements).join('|'), 'g')

  return name.replace(regex, (match) => replacements[match])
}

const formatted = replaceLetters(file)

await writeFile(
  resolve(import.meta.dirname, 'municipalities-formatted.json'),
  JSON.stringify(JSON.parse(formatted), null, 2),
  {
    encoding: 'utf-8',
  },
)
vercel[bot] commented 2 weeks ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
klimatkollen ✅ Ready (Inspect) Visit Preview May 15, 2024 11:06pm