Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporarily host REM on fly to fix the docs #2893

Merged
merged 1 commit into from
Jun 8, 2024

Conversation

JAForbes
Copy link
Collaborator

@JAForbes JAForbes commented Jun 8, 2024

Description

Fixes REM examples in the docs.

The documentation currently has a dead link as REM is no longer hosted on heroku. I think we should probably rewrite the example to not rely on an external service, but in the meantime I've hosted Leo's REM service on fly.io.

Motivation and Context

It's not good having broken documentation for the central example of the framework

How Has This Been Tested?

I updated the flems to use the new service and it worked. You can try it out here

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation change

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated docs/changelog.md

@dead-claudia
Copy link
Member

Can you also do a search and replace on gh-pages similar to what we (read: Pat) did years ago to add the red deprecation notice banner to past versions, and then file a PR against gh-pages with that until we add a long-term solution?

@dead-claudia dead-claudia merged commit 8c87814 into MithrilJS:next Jun 8, 2024
6 checks passed
@JAForbes JAForbes mentioned this pull request Jun 8, 2024
@JAForbes
Copy link
Collaborator Author

JAForbes commented Jun 8, 2024

Can you also do a search and replace on gh-pages similar to what we (read: Pat) did years ago to add the red deprecation notice banner to past versions, and then file a PR against gh-pages with that until we add a long-term solution?

Sorry missed this, can you link me to the PR where Pat did that and I'll do my best in a separate PR.

@dead-claudia
Copy link
Member

@JAForbes I'll do it. I have some spare time.

dead-claudia added a commit that referenced this pull request Jun 8, 2024
@dead-claudia
Copy link
Member

And fixed with a manual push: 487780f

Here's what I did, for future reference:

  1. Run git checkout upstream gh-pages

  2. Add /gh-pages-scripts to .git/info/exclude

  3. Save the following script to ./gh-pages-scripts/fix-link.mjs:

    import * as fs from "node:fs/promises"
    import * as path from "node:path"
    import LZString from "lz-string"
    import walk from "ignore-walk"
    
    if (process.argv.length < 4) {
        console.error(`
    Usage: node ./gh-pages-scripts/fix-link.mjs [source] [replacement]
    
    Run with the current working directory set the root of to a \`gh-pages\`
    checkout.
    `)
    }
    
    const source = process.argv[2]
    const replacement = process.argv[3]
    
    const flemsPattern = /flems\.io\/#0=([A-Za-z0-9+-]+)/
    
    function flemsReplacer(_, data) {
        const parsed = JSON.parse(LZString.decompressFromEncodedURIComponent(data))
    
        if (Array.isArray(parsed.files)) {
            for (const file of parsed.files) {
                if (typeof file.name === "string") {
                    file.name = file.name.replaceAll(source, replacement)
                }
                if (typeof file.content === "string") {
                    file.content = file.content.replaceAll(source, replacement)
                }
            }
        }
    
        if (Array.isArray(parsed.links)) {
            for (const file of parsed.links) {
                if (typeof file.name === "string") {
                    file.name = file.name.replaceAll(source, replacement)
                }
                if (typeof file.url === "string") {
                    file.url = file.url.replaceAll(source, replacement)
                }
            }
        }
    
        return `flems.io/#0=${LZString.compressToEncodedURIComponent(JSON.stringify(parsed))}`
    }
    
    async function visitFile(file) {
        file = path.resolve(file)
        const contents = await fs.readFile(file, {encoding: "utf-8"})
    
        const replaced = contents
            .replaceAll(source, replacement)
            .replace(flemsPattern, flemsReplacer)
    
        if (replaced !== contents) {
            console.log(`Replaced ${file}`)
            await fs.writeFile(file, replaced, {encoding: "utf-8"})
        }
    }
    
    const files = await walk({
        path: process.cwd(),
        ignoreFiles: [".gitignore"],
    })
    
    Promise.all(Array.from(files, visitFile))
  4. Run npm install ignore-walk lz-string

  5. Run node ./gh-pages-scripts/fix-link.mjs rem-rest-api.herokuapp.com mithril-rem.fly.dev

  6. Verify the file changes matches the changes in this issue.

  7. Run git push upstream gh-pages

This was referenced Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants