Skip to content

Conversation

@djpowers
Copy link
Contributor

This PR adds an "alias" key while generating https://documents.devdocs.io/docs.json, reusing the predefined aliases:

static ALIASES = {
angular: "ng",
"angular.js": "ng",
"backbone.js": "bb",
"c++": "cpp",
coffeescript: "cs",
crystal: "cr",
elixir: "ex",
javascript: "js",
julia: "jl",
jquery: "$",
"knockout.js": "ko",
kubernetes: "k8s",
less: "ls",
lodash: "_",
löve: "love",
marionette: "mn",
markdown: "md",
matplotlib: "mpl",
modernizr: "mdr",
"moment.js": "mt",
openjdk: "java",
nginx: "ngx",
numpy: "np",
pandas: "pd",
postgresql: "pg",
python: "py",
"ruby.on.rails": "ror",
ruby: "rb",
rust: "rs",
sass: "scss",
tensorflow: "tf",
typescript: "ts",
"underscore.js": "_",
};

Sample output for one doc item looks like so:

  {
    "name": "JavaScript",
    "slug": "javascript",
    "type": "mdn",
    "links": {
      "home": "https://developer.mozilla.org/en-US/docs/Web/JavaScript",
      "code": "https://github.com/mdn/content/tree/main/files/en-us/web/javascript"
    },
    "mtime": 1724174503,
    "db_size": 15314120,
    "attribution": "&copy; 2005&ndash;2024 MDN contributors.<br>\n      Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.",
    "alias": "js"
  },

This closes #2309, which provides more context on the rationale for this proposed change.

This implementation works, but could admittedly be more robust. I was hoping to avoid the aliases being defined in multiple places, and this seemed like the easiest approach to do so given we're working across JavaScript and Ruby.

Given that, if the team is open to this change, I'm happy to refactor if there's a preferred strategy. Thanks!

- read JavaScript file defining slug/alias mapping
- parse aliases object as Ruby hash
- add alias key to JSON output with value or null
@djpowers djpowers requested a review from a team as a code owner October 18, 2024 01:00
Copy link
Contributor

@simon04 simon04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you! I have moved the alias configuration to app.rb allowing its use without nasty JavaScript/JSON parsing.

@simon04 simon04 merged commit 002eb72 into freeCodeCamp:main Nov 17, 2024
1 of 2 checks passed
@chrisgrieser
Copy link
Contributor

chrisgrieser commented Nov 17, 2024

Thank you! Been waiting for this for my plugin that uses devdocs data.

When can we expect alias to be live at https://documents.devdocs.io/docs.json or https://devdocs.io/docs.json? (not meant to be pushy, just to plan when the corresponding change can be implemented on my end.)

@djpowers djpowers deleted the include-search-aliases-docs-json branch November 17, 2024 15:20
@djpowers
Copy link
Contributor Author

Awesome, thanks so much! I appreciate the refactoring improvement as well. It looks like the field is currently available from https://devdocs.io/docs/docs.json, however some aliases didn't seem to get mapped over. I see 11 results searching the JSON output for "alias": ", while it looks like there are 33 defined aliases. I didn't see any sort of pattern regarding what was included/omitted at a quick glance.

@chrisgrieser
Copy link
Contributor

I see 11 results searching the JSON output for "alias": ", while it looks like there are 33 defined aliases.

same here.

curl -sL "https://devdocs.io/docs.json" | grep "alias" | grep -v "null"
# → 12 aliases

curl -sL "https://documents.devdocs.io/docs.json" | grep "alias" | grep -v "null"
# → 0 aliases

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.

Include search aliases in the docs.json file

3 participants