From d51757c5ff663663a3d2b0ebf18cc095f38e9ccb Mon Sep 17 00:00:00 2001 From: Jay <110402935+jay-418@users.noreply.github.com> Date: Wed, 12 Jun 2024 16:30:47 -0600 Subject: [PATCH] migrated to github profile page for easier maintenance all code from pagemaker can now be found at https://github.com/getlantern/.github/tree/main/updater --- pagemaker/README.md | 21 -- pagemaker/go.mod | 18 -- pagemaker/go.sum | 21 -- pagemaker/links.yml | 48 ----- pagemaker/main.go | 285 --------------------------- pagemaker/main_test.go | 36 ---- pagemaker/outputs/footer.html | 26 --- pagemaker/outputs/footer.min.html | 1 - pagemaker/releases.yml | 43 ---- pagemaker/templates/README.md.tmpl | 122 ------------ pagemaker/templates/footer.html.tmpl | 24 --- pagemaker/translations/ar.json | 33 ---- pagemaker/translations/common.json | 33 ---- pagemaker/translations/en.json | 33 ---- pagemaker/translations/fa.json | 33 ---- pagemaker/translations/ru.json | 33 ---- pagemaker/translations/zh.json | 33 ---- 17 files changed, 843 deletions(-) delete mode 100644 pagemaker/README.md delete mode 100644 pagemaker/go.mod delete mode 100644 pagemaker/go.sum delete mode 100644 pagemaker/links.yml delete mode 100644 pagemaker/main.go delete mode 100644 pagemaker/main_test.go delete mode 100644 pagemaker/outputs/footer.html delete mode 100644 pagemaker/outputs/footer.min.html delete mode 100644 pagemaker/releases.yml delete mode 100644 pagemaker/templates/README.md.tmpl delete mode 100644 pagemaker/templates/footer.html.tmpl delete mode 100644 pagemaker/translations/ar.json delete mode 100644 pagemaker/translations/common.json delete mode 100644 pagemaker/translations/en.json delete mode 100644 pagemaker/translations/fa.json delete mode 100644 pagemaker/translations/ru.json delete mode 100644 pagemaker/translations/zh.json diff --git a/pagemaker/README.md b/pagemaker/README.md deleted file mode 100644 index 4a3fe38469..0000000000 --- a/pagemaker/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# pagemaker -Tool for automatically updating downloads page through source files. - -Do not edit main page README files or anything in the `outputs` directory, as these files are updated by *automatic actions*, from *template*, when *source files* or *translations* are changed. - -## source files -Update source files with newest information. -- [`links.yml`](./links.yml) -- [`releases.yml`](./releases.yml) - -## templates -Templates in the [templates](./templates) directory can be altered, and will affect all languages. -- [`README.md.tmpl`](./templates/README.md.tmpl) - -## translations -For every translation file in the [translations](./translations) directory, a new file will be made. -- [`common.json`](./translations/common.json) has permanent links and endonyms common to all translations - -## automatic actions -Any file changed in this directory will trigger an update of all translations using the _source files_, _templates_, and _translations_ cited above. -- [update.yml](../.github/workflows/update.yml) diff --git a/pagemaker/go.mod b/pagemaker/go.mod deleted file mode 100644 index be2f5d269c..0000000000 --- a/pagemaker/go.mod +++ /dev/null @@ -1,18 +0,0 @@ -module github.com/getlantern/lantern/pagemaker - -go 1.21.5 - -require ( - github.com/stretchr/testify v1.9.0 - gopkg.in/yaml.v2 v2.4.0 -) - -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/tdewolff/minify v2.3.6+incompatible // indirect - github.com/tdewolff/minify/v2 v2.20.19 // indirect - github.com/tdewolff/parse v2.3.4+incompatible // indirect - github.com/tdewolff/parse/v2 v2.7.12 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) diff --git a/pagemaker/go.sum b/pagemaker/go.sum deleted file mode 100644 index 5c279487e7..0000000000 --- a/pagemaker/go.sum +++ /dev/null @@ -1,21 +0,0 @@ -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/tdewolff/minify v2.3.6+incompatible h1:2hw5/9ZvxhWLvBUnHE06gElGYz+Jv9R4Eys0XUzItYo= -github.com/tdewolff/minify v2.3.6+incompatible/go.mod h1:9Ov578KJUmAWpS6NeZwRZyT56Uf6o3Mcz9CEsg8USYs= -github.com/tdewolff/minify/v2 v2.20.19 h1:tX0SR0LUrIqGoLjXnkIzRSIbKJ7PaNnSENLD4CyH6Xo= -github.com/tdewolff/minify/v2 v2.20.19/go.mod h1:ulkFoeAVWMLEyjuDz1ZIWOA31g5aWOawCFRp9R/MudM= -github.com/tdewolff/parse v2.3.4+incompatible h1:x05/cnGwIMf4ceLuDMBOdQ1qGniMoxpP46ghf0Qzh38= -github.com/tdewolff/parse v2.3.4+incompatible/go.mod h1:8oBwCsVmUkgHO8M5iCzSIDtpzXOT0WXX9cWhz+bIzJQ= -github.com/tdewolff/parse/v2 v2.7.12 h1:tgavkHc2ZDEQVKy1oWxwIyh5bP4F5fEh/JmBwPP/3LQ= -github.com/tdewolff/parse/v2 v2.7.12/go.mod h1:3FbJWZp3XT9OWVN3Hmfp0p/a08v4h8J9W1aghka0soA= -github.com/tdewolff/test v1.0.11-0.20231101010635-f1265d231d52/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pagemaker/links.yml b/pagemaker/links.yml deleted file mode 100644 index 9366c92fd9..0000000000 --- a/pagemaker/links.yml +++ /dev/null @@ -1,48 +0,0 @@ -# every listed site will be its own row for our public links -# and every row may have a list of links for each site below -# linked by that language's two digit code (ISO 639-1). -# bot is treated specially because it is multilingual -telegram: - bot: "https://t.me/lantern_official_bot" - fa: "https://t.me/LanternFarsi" - zh: "https://t.me/lantern_china" - ru: "https://t.me/lantern_russia" - uk: "https://t.me/lanternukraine" - be: "https://t.me/lantern_belarus" - ar: "https://t.me/lantern_uae" - fr: "https://t.me/LanternGuinea" -telegram_beta: - fa: "https://t.me/lanternbetaIR" - ru: "https://t.me/+pLVA7H6MU_Y2N2Vi" - uk: "https://t.me/+c_K4oFhv7NMzZjlh" - zh: "https://t.me/+n3SfwL0Ho7w1ODgz" - be: "https://t.me/+bRTww4oDsrsxY2Mx" - ar: "https://t.me/+cUgbK1eqrrE0MDQx" - fr: "https://t.me/+_G9WGtSTXvs3ZDQx" -instagram: - fa: "https://www.instagram.com/getlantern_fa/" - zh: "https://www.instagram.com/lanternio_ch/" - en: "https://www.instagram.com/getlantern/" - uk: "https://www.instagram.com/getlantern_ua/" - be: "https://www.instagram.com/getlantern_belarus/" - ru: "https://www.instagram.com/lantern.io_ru" - ar: "https://www.instagram.com/lanternio_uae/" - fr: "https://www.instagram.com/lanternio_guinea/" -twitter: - zh: "https://twitter.com/getlantern_CN" - fr: "https://twitter.com/getlantern_gu" - ar: "https://twitter.com/getlantern_UAE" - fa: "https://twitter.com/getlantern_fa" - en: "https://twitter.com/getlantern" - ru: "https://twitter.com/Lantern_Russia" - uk: "https://twitter.com/LanternUA" - be: "https://twitter.com/LanternBelarus" -github: - zh: https://github.com/getlantern/lantern-forum-cn/discussions - fa: https://github.com/getlantern/lantern-forum-fa/discussions - en: https://github.com/getlantern/lantern-forum-en/discussions - ru: https://github.com/getlantern/lantern-forum-ru/discussions - be: https://github.com/getlantern/lantern-forum-belarus - ar: https://github.com/getlantern/lantern-forum-uae/discussions - uk: https://github.com/getlantern/lantern-forum-ukraine/discussions - diff --git a/pagemaker/main.go b/pagemaker/main.go deleted file mode 100644 index 1822c338f1..0000000000 --- a/pagemaker/main.go +++ /dev/null @@ -1,285 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "html/template" - "os" - "path" - "path/filepath" - "strings" - - "github.com/tdewolff/minify/v2" - "github.com/tdewolff/minify/v2/html" - yaml "gopkg.in/yaml.v2" -) - -const ( - linksFile = "links.yml" // social media - releaseFile = "releases.yml" // release notes - commonFile = "common.json" // endonyms & shared links - templateSuffix = ".tmpl" - templateDir = "templates" - translationsDir = "translations" - outputDir = "outputs" -) - -var ( - commonPath = path.Join(translationsDir, commonFile) - debug = false -) - -type site map[string]string // an entry for each language -type sites map[string]site // e.g. links.yml -type translations map[string]string // e.g. en.json -type releases []map[string][]string // e.g. releases.yml - -// downloads page -type page struct { - Sites sites // sites to link - Translations translations // per language - Common translations // universal - Releases releases // release notes -} - -func init() { - if _, ok := os.LookupEnv("DEBUG"); ok { - fmt.Println("DEBUG mode enabled") - debug = true - } -} - -func main() { - pwd, err := os.Getwd() - if err != nil { - fmt.Printf("unable to get working directory: %v\n", err) - os.Exit(1) - } - parentDir := filepath.Dir(pwd) - - // download page: https://github.com/getlantern/lantern - err = updateDownloadsPages(parentDir) - if err != nil { - fmt.Printf("unable to update page: %v\n", err) - os.Exit(1) - } - - // email footer: downloads@getlantern.org (et al.) - err = updateFooter(outputDir) - if err != nil { - fmt.Printf("unable to update footer: %v\n", err) - os.Exit(2) - } - - fmt.Println("🎉 Updates complete!") -} - -// updateFooter writes a single, minimal, language-agnostic text for -// downloads@getlantern.org [TODO or help desk email footers] -func updateFooter(destinationDir string) error { - // English is the default (e.g. EXAMPLE.md, EXAMPLE.zh.md, EXAMPLE.ar.md, etc.) - // File will be written to destinationDir. - baseName := "footer.html" - templateName := fmt.Sprintf("%s%s", baseName, templateSuffix) - template := filepath.Join(templateDir, templateName) - outFilename := filepath.Join(destinationDir, baseName) - if debug { - fmt.Printf("Creating '%s'\n", outFilename) - } - defaultLang := "en.json" - filePath := path.Join(translationsDir, defaultLang) - page, err := loadInfo(filePath) - if err != nil { - return fmt.Errorf("unable to load info for '%s': %w", filePath, err) - } - err = createFromTemplate(page, template, outFilename) - if err != nil { - return fmt.Errorf("unable to update footer: %w", err) - } - // also minify the output - err = makeMinifiedCopy(outFilename) - if err != nil { - return fmt.Errorf("unable to minify footer: %w", err) - } - return nil -} - -// minify takes a file path and minifies the html contents into a new file -// ending in .min.html -func makeMinifiedCopy(filepath string) error { - m := minify.New() - m.AddFunc("text/html", html.Minify) - data, err := os.ReadFile(filepath) - if err != nil { - return fmt.Errorf("unable to read file '%s': %w", filepath, err) - } - minified, err := m.String("text/html", string(data)) - if err != nil { - return fmt.Errorf("unable to minify data: %w", err) - } - extension := path.Ext(filepath) - bareName := strings.Replace(filepath, extension, "", -1) - minifiedPath := fmt.Sprintf("%s.min%s", bareName, extension) - - err = os.WriteFile(minifiedPath, []byte(minified), 0644) - if err != nil { - return fmt.Errorf("unable to write minified data: %w", err) - } - return nil -} - -// updateDownloadsPages takes a desired target output EXAMPLE.md and uses template EXAMPLE.tmpl.md -// to create a new file for each source translation in the translations directory. -// -// English is the default (e.g. EXAMPLE.md, EXAMPLE.zh.md, EXAMPLE.ar.md, etc.). -// File will be written to destinationDir. -func updateDownloadsPages(destinationDir string) error { - baseName := "README.md" - // we want to update the downloads page for every available translation - files, err := os.ReadDir(translationsDir) - if err != nil { - return fmt.Errorf("unable to load translations: %w", err) - } - for _, file := range files { - name := file.Name() - if name == commonFile { - continue - } - filePath := path.Join(translationsDir, name) - lang := strings.Replace(name, filepath.Ext(name), "", -1) - - page, err := loadInfo(filePath) - if err != nil { - return fmt.Errorf("unable to load info for '%v': %w", lang, err) - } - - templateName := fmt.Sprintf("%s%s", baseName, templateSuffix) - template := filepath.Join(templateDir, templateName) - outFilename := filepath.Join(destinationDir, baseName) - // format filename for non-English languages (e.g. EXAMPLE.zh.md) - if lang != "en" { - splitTarget := strings.Split(baseName, ".") - if len(splitTarget) != 2 { - return fmt.Errorf("invalid target; could not be formatted: %s", baseName) - } - outFilename = filepath.Join( - destinationDir, - fmt.Sprintf("%s.%s.%s", splitTarget[0], lang, splitTarget[1]), - ) - // fmt.Sprintf("%s.%s.%s", splitTarget[0], lang, splitTarget[1]) - } - if debug { - fmt.Printf("Creating '%s'\n", outFilename) - } - err = createFromTemplate(&page, template, outFilename) - if err != nil { - return fmt.Errorf("unable to update page: %w", err) - } - } - return nil -} - -// loadInfo intakes a language then parses files and returns a struct -// using common resources, files, and the language's translations -func loadInfo(translationFile string) (page, error) { - var sites sites - err := readUnmarshalFile(linksFile, &sites) - if err != nil { - return page{}, fmt.Errorf("unable to load sites: %w", err) - } - if debug { - fmt.Printf("sites:\n%v\n\n", sites) - } - - var releases releases - err = readUnmarshalFile(releaseFile, &releases) - if err != nil { - return page{}, fmt.Errorf("unable to load releases: %w", err) - } - if debug { - fmt.Printf("releases:\n%v\n", releases) - } - - // not language specific - var common translations - err = readUnmarshalFile(commonPath, &common) - if err != nil { - return page{}, fmt.Errorf("unable to load common strings: %w", err) - } - if debug { - fmt.Printf("common:\n%v\n", common) - } - - // language specific - - var translations translations - err = readUnmarshalFile(translationFile, &translations) - if err != nil { - return page{}, fmt.Errorf("unable to load translations: %w", err) - } - if debug { - fmt.Printf("translations:\n%v\n", translations) - } - - page := page{ - Sites: sites, - Common: common, - Translations: translations, - Releases: releases, - } - if debug { - fmt.Printf("page: %+v\n", page) - } - return page, nil -} - -// readUnmarshalFile reads a file, then attempts to unmarshal into the provided struct -func readUnmarshalFile(filePath string, destination any) error { - data, err := os.ReadFile(filePath) - if err != nil { - return fmt.Errorf("error reading file '%s': %w", filePath, err) - } - if debug { - fmt.Printf("read %v bytes from '%s'\n", len(data), filePath) - } - switch filepath.Ext(filePath) { - case ".json": - err = json.Unmarshal(data, destination) - if err != nil { - return fmt.Errorf("error unmarshalling JSON file '%s': %w", filePath, err) - } - case ".yaml", ".yml": - err = yaml.Unmarshal(data, destination) - if err != nil { - return fmt.Errorf("error unmarshalling YAML file '%s': %w", filePath, err) - } - default: - return fmt.Errorf("unsupported file type: %s", filePath) - } - return nil -} - -// createFromTemplate parses a source file, applies a template, and writes the output to a file, -// all passed as paths. -func createFromTemplate(dataStruct any, templateFile string, outputFile string) error { - tmpl, err := template.ParseFiles(templateFile) - if err != nil { - return fmt.Errorf("failed to parse template: %w", err) - } - f, err := os.Create(outputFile) - if err != nil { - return fmt.Errorf("failed to create file: %w", err) - } - defer f.Close() - if debug { - fmt.Printf("preparing to write structured data to '%s':\n%+v\n", - outputFile, - dataStruct, - ) - } - err = tmpl.Execute(f, dataStruct) - if err != nil { - return fmt.Errorf("failed to execute template: %w", err) - } - return nil -} diff --git a/pagemaker/main_test.go b/pagemaker/main_test.go deleted file mode 100644 index c35816680d..0000000000 --- a/pagemaker/main_test.go +++ /dev/null @@ -1,36 +0,0 @@ -package main - -import ( - "path" - "testing" - - "github.com/stretchr/testify/require" -) - -func TestReadUnmarshalFile(t *testing.T) { - var sites sites - err := readUnmarshalFile(linksFile, &sites) - require.NoError(t, err) - require.NotNil(t, sites) - t.Logf("%v sites found: %+v", len(sites), sites) -} - -func TestParseJSON(t *testing.T) { - var common translations - filePath := path.Join(translationsDir, "common.json") - err := readUnmarshalFile(filePath, &common) - require.NoError(t, err) - require.NotNil(t, common) - t.Logf("file parsed: %+v", common) -} - -func TestLoadInfo(t *testing.T) { - filePath := path.Join(translationsDir, "en.json") - info, err := loadInfo(filePath) - require.NoError(t, err) - require.NotNil(t, info) - t.Logf("info.Translations: %+v\n", info.Translations) - t.Logf("info.Common: %+v\n", info.Common) - t.Logf("info.Releases: %+v\n", info.Releases) - t.Logf("info.Sites: %+v\n", info.Sites) -} diff --git a/pagemaker/outputs/footer.html b/pagemaker/outputs/footer.html deleted file mode 100644 index dc471fa0f1..0000000000 --- a/pagemaker/outputs/footer.html +++ /dev/null @@ -1,26 +0,0 @@ - - -
- | {{ $tx.stable }} | -{{ $tx.app_store }} | -{{ $tx.beta }} | -
---|---|---|---|
{{ $tx.win }} | -
- {{ $tx.win10 }} - {{ $tx.win10 }} - {{ $tx.win10 }} - {{ $tx.win7 }} - |
- - | - {{ $tx.win10 }} - | -
{{ $tx.android }} | -
- {{ $tx.android6 }} - {{ $tx.android6 }} - {{ $tx.android6 }} - |
- - {{ $tx.android6 }} - | -- {{ $tx.android6 }} - | -
{{ $tx.macos }} | -
- {{ $tx.osx }} - {{ $tx.osx }} - {{ $tx.osx }} - |
- - | - {{ $tx.osx }} - | -
{{ $tx.ios }} | -- | - {{ $tx.ios11 }} - | -- |
{{ $tx.linux32 }} | -
- {{ $tx.ubuntu32 }} - {{ $tx.ubuntu32 }} - |
- - | - {{ $tx.ubuntu32 }} - | -
{{ $tx.linux64 }} | -
- {{ $tx.ubuntu64 }} - {{ $tx.ubuntu64 }} - |
- - | - {{ $tx.ubuntu64 }} - | -