Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 5

Accessing repository topics in github pages theme

Solved! Go to Solution.

Is it possible to retrieve the topics for a repository in a theme?

I would like to list all repositories which have a certain topic, but I haven't been able to find a way to this. Is anyone aware of a method of doing this? Otherwise it might be a nice feature to add.

 

An example of what it might look like:

{% for repository in site.github.public_repositories %}
{% if repository.topics contains "production_ready" %} <a href="{{ repository.name }}">{{ repository.name }}</a> (<a href="{{ repository.html_url }}">repo</a>) </br> {% endif %} {% endfor %}
4 Replies
Community Manager
Message 2 of 5

Re: Accessing repository topics in github pages theme

Something like this would most likely need to be a Jekyll plugin. You could search the list of GitHub repositories that have the jekyll-plugin topic perhaps? I didn't find anything pre-made that seemed to fit what you're going after, but perhaps there is something pre-made that will get you started?

 

I hope that helps!

Solution
Copilot Lvl 2
Message 3 of 5

Re: Accessing repository topics in github pages theme

I found an alternative method using the repository description rather than topics, but thanks for the suggestion!

 

Here is what I'm doing in case anyone is interested :

I'm adding "Category:<label>" at the end of the description and then using this to create arrays of repo names:

 

{% assign productionReady = '' | split: '' %}
{% assign experimental = '' | split: '' %}

{% for repository in site.github.public_repositories %}
  {% assign category = repository.description | split: "Category:" | last %}
  {% assign repoName = repository.name | split: '@@@' %}
    {% if category == "Production-Ready" %}
      {% assign productionReady = productionReady | concat: repoName %}
    {% endif %}
    {% if category == "Experimental" %}
      {% assign experimental = experimental | concat: repoName %}
    {% endif %}
{% endfor %}

Then looping over these arrays I can make links.

 

Copilot Lvl 2
Message 4 of 5

Re: Accessing repository topics in github pages theme

I'd love to have topics available in the Repository Metadata. I assume the reason it's not in there is because of the following disclaimer in the API documentation:

 


Note: The topics property for repositories on GitHub is currently available for developers to preview. To view the topics property in calls that return repository results, you must provide a custom media type in the Accept header:

application/vnd.github.mercy-preview+json

 

It would be neat if we could opt-in to preview features like this with something like preview: true in _config.yml.

Community Manager
Message 5 of 5

Re: Accessing repository topics in github pages theme

If you have a feature that you'd like to suggest for Jekyll, which is how you would get a change to how the `_config.yml` behaves, you can file a feature request on the Jekyll project on GitHub.

 

I hope that helps!