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

Add field to docs.json denoting available aliases #2344

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

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
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
1 participant