diff --git a/content/actions/index.md b/content/actions/index.md index ad0099dfe825..fa449ba6d9df 100644 --- a/content/actions/index.md +++ b/content/actions/index.md @@ -60,105 +60,26 @@ versions: +{% assign actionsCodeExamples = site.data.variables.action_code_examples %} +{% if actionsCodeExamples %}

Code examples

+
+ +
+
- - - - - - + {% render 'code-example-card' for actionsCodeExamples as example %} +
+ + + +
+
{% octicon "search" width="24" %}
+

Sorry, there is no result for

+

It looks like we don't have an example that fits your filter.
Try another filter or add your code example

+ Learn how to add a code example {% octicon "arrow-right" %}
+{% endif %} diff --git a/data/variables/action_code_examples.yml b/data/variables/action_code_examples.yml new file mode 100644 index 000000000000..a0f12b03840c --- /dev/null +++ b/data/variables/action_code_examples.yml @@ -0,0 +1,131 @@ +- title: Starter workflows + description: Workflow files for helping people get started with GitHub Actions + languages: TypeScript + href: actions/starter-workflows + tags: + - official + - workflows +- title: Example services + description: Example workflows using service containers + languages: JavaScript + href: actions/example-services + tags: + - service containers +- title: Declaratively setup GitHub Labels + description: GitHub Action to declaratively setup labels across repos + languages: JavaScript + href: lannonbr/issue-label-manager-action + tags: + - issues + - labels +- title: Declaratively sync GitHub lables + description: GitHub Action to sync GitHub labels in the declarative way + languages: 'Go, Dockerfile' + href: micnncim/action-label-syncer + tags: + - issues + - labels +- title: Add releases to GitHub + description: Publish Github releases in an action + languages: 'Dockerfile, Shell' + href: elgohr/Github-Release-Action + tags: + - releases + - publishing +- title: Publish a docker image to Dockerhub + description: A Github Action used to build and publish Docker images + languages: 'Dockerfile, Shell' + href: elgohr/Publish-Docker-Github-Action + tags: + - docker + - publishing + - build +- title: Create an issue using content from a file + description: A GitHub action to create an issue using content from a file + languages: 'JavaScript, Python' + href: peter-evans/create-issue-from-file + tags: + - issues +- title: Publish GitHub Releases with Assets + description: GitHub Action for creating GitHub Releases + languages: 'TypeScript, Shell, JavaScript' + href: softprops/action-gh-release + tags: + - releases + - publishing +- title: GitHub Project Automation+ + description: Automate GitHub Project cards with any webhook event. + languages: JavaScript + href: alex-page/github-project-automation-plus + tags: + - projects + - automation + - issues + - pull requests +- title: Run GitHub Actions Locally with a web interface + description: Runs GitHub Actions workflows locally (local) + languages: 'JavaScript, HTML, Dockerfile, CSS' + href: phishy/wflow + tags: + - local-development + - devops + - docker +- title: Run your GitHub Actions locally + description: Run GitHub Actions Locally in Terminal + languages: 'Go, Shell' + href: nektos/act + tags: + - local-development + - devops + - docker +- title: Build and Publish Android debug APK + description: Build and release debug APK from your Android project + languages: 'Shell, Dockerfile' + href: ShaunLWM/action-release-debugapk + tags: + - android + - build +- title: Generate sequential build numbers for GitHub Actions + description: GitHub action for generating sequential build numbers. + languages: JavaScript + href: einaregilsson/build-number + tags: + - build + - automation +- title: GitHub actions to push back to repository + description: Push Git changes to GitHub repository without authentication difficulties + languages: 'JavaScript, Shell' + href: ad-m/github-push-action + tags: + - publishing +- title: Generate release notes based on your events + description: Action to auto generate a release note based on your events + languages: 'Shell, Dockerfile' + href: Decathlon/release-notes-generator-action + tags: + - releases + - publishing +- title: Create a GitHub wiki page based on the provided markdown file + description: Create a GitHub wiki page based on the provided markdown file + languages: 'Shell, Dockerfile' + href: Decathlon/wiki-page-creator-action + tags: + - wiki + - publishing +- title: Label your Pull Requests auto-magically (using committed files) + description: >- + Github action to label your pull requests auto-magically (using committed + files) + languages: 'TypeScript, Dockerfile, JavaScript' + href: Decathlon/pull-request-labeler-action + tags: + - projects + - issues + - labels +- title: Add Label to your Pull Requests based on the author team name + description: Github action to label your pull requests based on the author name + languages: 'TypeScript, JavaScript' + href: JulienKode/team-labeler-action + tags: + - pull request + - labels diff --git a/includes/code-example-card.html b/includes/code-example-card.html new file mode 100644 index 000000000000..a1a1d8c5be15 --- /dev/null +++ b/includes/code-example-card.html @@ -0,0 +1,20 @@ +
+ +
+

{{ example.title }}

+

{{ example.description }}

+
+ {% for tag in example.tags %} + {{ tag }} + {% endfor %} +
+
+ +
+
diff --git a/javascripts/filter-code-examples.js b/javascripts/filter-code-examples.js new file mode 100644 index 000000000000..c6592672e418 --- /dev/null +++ b/javascripts/filter-code-examples.js @@ -0,0 +1,92 @@ +function filterCards (cards, value) { + const noResults = document.querySelector('.js-code-example-no-results') + const matchReg = new RegExp(value, 'i') + + // Track whether or not we had at least one match + let hasMatches = false + + for (let index = 0; index < cards.length; index++) { + const card = cards[index] + + // Filter was emptied + if (!value) { + // Make sure we don't show the "No results" blurb + hasMatches = true + + // Hide all but the first 6 + if (index > 5) { + card.classList.add('d-none') + } else { + card.classList.remove('d-none') + } + + continue + } + + // Check if this card matches + const { title, description, tags } = card.dataset + const cardMatches = ( + matchReg.test(title) || + matchReg.test(description) || + matchReg.test(tags) + ) + + if (cardMatches) { + card.classList.remove('d-none') + hasMatches = true + } else { + card.classList.add('d-none') + } + } + + // If there wasn't at least one match, show the "no results" text + if (!hasMatches) { + document.querySelector('.js-code-example-filter-value').textContent = value + noResults.classList.remove('d-none') + } else { + noResults.classList.add('d-none') + } +} + +export default function filterCodeExamples () { + const filter = document.querySelector('.js-code-example-filter') + if (!filter) return + + const cards = Array.from(document.querySelectorAll('.js-code-example-card')) + const showMoreButton = document.querySelector('.js-code-example-show-more') + + filter.addEventListener('keyup', evt => { + const value = evt.currentTarget.value + + // Show or hide the "Show more" button if there is a value + if (value) showMoreButton.classList.add('d-none') + else showMoreButton.classList.remove('d-none') + + filterCards(cards, value) + }) + + showMoreButton.addEventListener('click', evt => { + // Number of cards that are currently visible + const numShown = cards.filter(card => !card.classList.contains('d-none')).length + // We want to show 6 more + const totalToShow = numShown + 6 + + for (let index = numShown; index < cards.length; index++) { + const card = cards[index] + + // If the card we're at is less than the total number of cards + // we should show, show this one + if (index < totalToShow) { + card.classList.remove('d-none') + } else { + // Otherwise, we've shown the ones we intend to so exit the loop + break + } + } + + // They're all shown now, we should hide the button + if (totalToShow === cards.length) { + evt.currentTarget.style.display = 'none' + } + }) +} diff --git a/javascripts/index.js b/javascripts/index.js index 8d381eff36fa..a6d6f4649ebf 100644 --- a/javascripts/index.js +++ b/javascripts/index.js @@ -15,6 +15,7 @@ import experiment from './experiment' import copyCode from './copy-code' import { fillCsrf } from './get-csrf' import initializeEvents from './events' +import filterCodeExamples from './filter-code-examples' document.addEventListener('DOMContentLoaded', async () => { displayPlatformSpecificContent() @@ -32,4 +33,5 @@ document.addEventListener('DOMContentLoaded', async () => { experiment() copyCode() initializeEvents() + filterCodeExamples() }) diff --git a/layouts/product-landing.html b/layouts/product-landing.html index 8c87a431694d..4ffcedfc368d 100644 --- a/layouts/product-landing.html +++ b/layouts/product-landing.html @@ -30,7 +30,7 @@

{{ page.shortTitle }}