Skip to content

Content structure for code examples #68

Closed

Description

@fdoflorenzano

Right now, we can add code examples to a video in it's corresponding JSON file:

"codeExamples": [
   {
     "title": "Random Square Design",
     "description": "Using the random() function to draw randomly sized squares",
     "image": "https://processing.org/static/b8793fda1d825d4d138038d97deff7a2/b2a35/GameOfLife.webp",
     "language": "p5js",
     "folder": "folderWithCode",
     "webEditor": "Sl8ml_Lz8"
   },
...
]

and the setup allows a src folder to be added alongside this index.json file, where multiple folders can be sub-added and can be referenced using the "folder" property of a code example specification.

To continue with #57 and #66, we need to add the images into this whole setup. One comes to mind:

We keep a similar approach to what we have now and add the possibility of creating an images folder on each video folder that contains only images. All these images can be then referenced by the index.json file of the video, specifically by an "image" property of code examples. This can also help us to add images in other parts, like for thumbnails for links.

So folders for videos would be:

[videos|journeys]
└─ video-slug
   ├─ index.json
   ├─ src
   │  ├─ code-folder-1
   │  └─ ...
   ├─ images
   │  ├─ image1.png
   │  └─ ...
   └─ contributions
      ├─ contribution-slug-1.json
      ├─ contribution-slug-2.json
      └─ ...

and the code examples portion of index.json file would be:

"codeExamples": [
   {
     "title": "Random Square Design",
     "description": "Using the random() function to draw randomly sized squares",
     "image": "image1.png",
     "language": "p5js",
     "folder": "code-folder-1",
     "webEditor": "Sl8ml_Lz8"
   },
...
]

Also, as I'm writing this, I realize I'm not sure if every code examples would have a corresponding code folder with files. Maybe sometimes it just lives in the p5editor?

Activity

  1. fdoflorenzano commented on Feb 14, 2022

    @fdoflorenzano
    CollaboratorAuthor

    Sorry for the assignment back and forth, I was trying to see if multiple people could be assigned. AGAIN failed haha GitHub could make that more clear.

  2. bravomartin commented on Feb 15, 2022

    @bravomartin
    Collaborator

    In addition to adding the images, I get the impression from this comment that the code examples won't necessarily be local files or include only the p5 editors.

    Currently, we have:

    {
      ... // other props
      folder // path to a local folder containing the code
      webEditor // an optional id (for p5 code only) that permits linking a web-editor project 
    }

    @shiffman what are all the cases we should consider?

    Going back to the comment, we see the need for a "secondary" link to the processing port.
    Are there other ports that should be linked?
    Are there currently / do you foresee links to other external web editors?

    Knowing this we can change the data structure to be able to accommodate these cases and update it together with the image changes.

  3. shiffman commented on Feb 15, 2022

    @shiffman
    Member

    Thanks @bravomartin for helping find clarity in this! This has come up in my discussion with @klinegareth. I think we can assume the following possible categories for links to code:

    • p5: a link to the p5 web editor
    • Processing: a link to a Processing sketch (most likely a GitHub link but I'm not sure yet, it would be nice if this auto-downloaded the sketch but that is not entirely necessary and lower priority.)
    • GitHub: a general link to GitHub repo (I'd be using this for things like Discord Bot examples or other node projects)
    • URL: At the moment, I don't have a specific need for this but building in a generic URL might be nice just in case I use some other editor.

    So every example would have at least 1 of the 4 above categories. Most of them would have all three: p5 + Processing + GitHub, but some might have only 1 or 2.

    Also, I think it would be best to not upload the example code to the website repo it's just adding too much, so I will figure out a way to manage any links to GitHub to be to other external repos. So the idea of a "folder" is no longer necessary!

    Does this help? I'd be glad to jump on a call to discuss! @klinegareth feel free to chime in!

  4. bravomartin commented on Feb 15, 2022

    @bravomartin
    Collaborator

    Thanks for the clarification, @shiffman and @klinegareth. It does make sense to not have the code in the repo, as it could easily make the repo grow a lot. We went over with @fdoflorenzano and we suggest the following, to make sure we're future-proofing it without complicating the structure:

    codeUrl: // URL pointing at the code
    editorUrl: // URL pointing at the editor
    

    This way, we can be completely agnostic of both where the code lives, and what editor to use. The code could even remain in the repo, and you would just have to link the full URL to it. Same case for editors. You can still use p5 by adding the full URL instead of the code, and if makes sense in the future, use codepen, codesandbox, etc. for other examples without any issue.

    Additionally, we can continue using the codeDownload feature by adding a check in the build process, adding it if github.com is found in the codeUrl.

    Let us know if that works for you.

  5. shiffman commented on Feb 15, 2022

    @shiffman
    Member

    Ah, I see what you are saying, however, I think that since 95%of the code examples right now are p5 or Processing, it would be helpful to build specifically for those two environments. I understand the need to future-proof but as far as my process goes, I generally build a p5 and Processing version of every coding challenge (with only 1 or 2 exceptions). And I would love to see the logos in the little bar! Something along the lines of:

    image

    Could we do:

    p5-url:
    Processing-url:
    other-url:
    

    The the main thumbnail or title can go link to one of those in that order, p5 by default but Processing or just a code-url if nothing else?

    The distinction between "code" vs. "editor" is less meaningful to the audience than which language or environment—that's what they are looking for.

    Does that make sense?
    Dan

  6. fdoflorenzano commented on Feb 16, 2022

    @fdoflorenzano
    CollaboratorAuthor

    Hey @shiffman ! I guess our confusion came from us thinking of each code example entry as a single language reference code base, that's why the "language"property was present and all links initially were thought as referring to the same code base but in different forms (like a web editor and files). I think that's the way the current site shows them also, as single language strips.

    So from what we've gathered thus far in this discussion, you are proposing too a way of adding multiple languages even for a single code base. So maybe something like the following could fit what you are looking for:

    {
        "title": "Video title",
        "codeExamples": [
        {
            "title": "Random Square Design",
            "description": "Using the random() function to draw randomly sized squares",
            "image": "codeExample1.png",
            "urls": {
                "p5": "https://editor.p5js.org/codingtrain/sketches/KTVfEcpWx",
                "processing": "https://github.com/CodingTrain/website/tree/main/CodingChallenges/CC_005_Space_invaders/Processing/CC_005_Space_invaders",
                "other": "https://github.com/CodingTrain/website/tree/main/CodingChallenges/CC_166_Ascii_Image/ascii-video"
            }
        }
        ]
    }

    The "urls" property object can gather all available links to web editors or source code available for the example. This can be extended eventually to new languages, like node and maybe expect a "node" key. "other" would be the fallback in case none of the other languages are set.

    This would then scrap the "language", "webEditor" and "folder" properties we initially proposed. And therefore we expect the code not to live in this repo and site, so we also don't expect a src subfolder in the specific video folder.

    On a separate note it's the front-end. As you last mentioned, we can set a priority order for which link gets opened when clicking the title or thumbnail. Clicking the specific logo would open the specific URL. "other" gets the book emoji that appears in the previous screen shot, and the save emoji only appears if "other" is a GitHub link.

    Does that work? @shiffman

    Also, the images discussion kinda got lost in this discussion. Would love to hear your thoughts on what I initially proposed for an "image" property that references the relative path from an images subfolder in the specific video folder.

  7. shiffman commented on Feb 16, 2022

    @shiffman
    Member

    Yes, this would work great!! I like where we are landing with this!

    And yes I think the images subfolder idea works for me! @klinegareth do you have any thoughts about that?

    If it is easier I would also be ok with just one giant directory of example thumbnails (I know this is different than my usual desire of having subfolders). But probably organizing them per video is better!

  8. NwE0kmCE commented on Feb 16, 2022

    @NwE0kmCE
    Collaborator

    @shiffman @fdoflorenzano This all looks great! I've been ignoring making src folders when adding examples to the site anyways, since it seemed redundant if a web editor link was already there. I think organizing thumbnails per video is probably the best way to go about it, unless @shiffman you expect them to get reused for different videos

  9. shiffman commented on Feb 16, 2022

    @shiffman
    Member

    Great, let's more forward and execute this new data format! Yay!

  10. shiffman commented on Feb 17, 2022

    @shiffman
    Member

    Assigning to @klinegareth now that this is resolved and merged to start updating all of the existing video pages (tracks and challenges) to have this new format:

    {
        "title": "Video title",
        "codeExamples": [
        {
            "title": "Random Square Design",
            "description": "Using the random() function to draw randomly sized squares",
            "image": "codeExample1.png",
            "urls": {
                "p5": "https://editor.p5js.org/codingtrain/sketches/KTVfEcpWx",
                "processing": "https://github.com/CodingTrain/website/tree/main/CodingChallenges/CC_005_Space_invaders/Processing/CC_005_Space_invaders",
                "other": "https://github.com/CodingTrain/website/tree/main/CodingChallenges/CC_166_Ascii_Image/ascii-video"
            }
        }
        ]
    }

    As part of this process, when it is a Processing link or any other GitHub link, let's create a new repo (?)—this might need a separate issue / discussion—and put the example code there. This way we no longer link to code found in the old website repo or this website repo. Code examples always live somewhere else on their own, either in a stand-alone repo or a repo that is a collection of examples, e.g. https://github.com/CodingTrain/Coding-Challenges.

  11. NwE0kmCE commented on Feb 24, 2022

    @NwE0kmCE
    Collaborator

    Merged PR #73, using new code example format from here on out and branching from main to add new content.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions