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

feat: dynamically set curriculum href #130

Merged
merged 22 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions javascripts/discourse/api-initializers/freecodecamp.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,25 @@ export default apiInitializer("0.8", (api) => {
</div>
</nav>
</template>);

const curriculum_slugs = settings.curriculum_slug.split('|');
const languages = settings.languages.split('|');

api.onPageChange((_url, _title) => {
const curriculum_nav = document.querySelector('.curriculum-nav');
const category = api.container.lookup("service:discovery").category;

if (!curriculum_nav) {
return;
}
// Reset to default href;
curriculum_nav.href = settings.curriculum_src;

languages.forEach((lang, i) => {
if (lang.toLowerCase() === category?.slug?.toLowerCase()) {
const url_path = new URL(curriculum_slugs[i], settings.curriculum_src);
curriculum_nav.href = url_path.href;
}
});
})
});
39 changes: 35 additions & 4 deletions settings.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,44 @@
# Forum languages
# These settings are needed because forum languages and /learn/<language> are different
languages:
default: espanol|chinese|chinese-traditional|italiano|portugues|ukrainian|japanese|german
description: "Languages forum slug names which are also available on freeCodeCamp curriculum"
type: list
list_type: simple
choices:
- espanol
- chinese
- chinese-traditional
- italiano
- portugues
- ukrainian
- japanese
- german

# Navigation
curriculum_title:
default: Visit the Curriculum
description: "This text will be displayed in the curriculum navigation item"
description: "Text displayed in the curriculum navigation item"
curriculum_title_short:
default: Curriculum
description: "This is the short version of curriculum title used for mobile devices"
description: "The short version of curriculum title used for mobile devices"
curriculum_src:
default: https://www.freecodecamp.org/learn
description: "This the link to related language curriculum"
default: https://www.freecodecamp.org/
description: "The link to related language curriculum"
curriculum_slug:
default: espanol|chinese|chinese-traditional|italian|portuguese|ukrainian|japanese|german
description: "Slug attached to curriculum_src"
type: list
list-type: simple
choices:
- espanol
- chinese
- chinese-traditional
- italian
- portuguese
- ukrainian
- japanese
- german

# Analytics
Google_Tag_Manager:
Expand Down
Loading