Skip to content

Refactor: Use bundled Fediverse instance list and NodeInfo #477

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

reuixiy
Copy link
Owner

@reuixiy reuixiy commented Jun 7, 2025

This commit addresses issue #471 by changing how the "Share to Fediverse" feature handles Fediverse instance data and software name detection.

Key changes:

  1. Bundled Instance List: The theme now uses a locally bundled list of Fediverse instances stored in data/fedi_instances.json for the autocomplete functionality in fedishare.html. This replaces the previous method of dynamically fetching this list from api.fediverse.observer. A fallback to a minimal hardcoded list is implemented if the JSON file is missing.

  2. NodeInfo for Software Name: The JavaScript logic in fedishare.js for determining the software of a Fediverse instance has been updated to primarily rely on the NodeInfo discovery protocol (/.well-known/nodeinfo). The previous check against data from Fediverse Observer has been removed. A fallback to "mastodon" is retained if NodeInfo discovery fails.

  3. Removed Dynamic Fetching Code: All Hugo templating and JavaScript code related to dynamically fetching instance lists and software names from Fediverse Observer has been removed. The site parameter .Site.Params.fetchFediverseInstances is no longer used by the theme.

These changes make the feature more reliable by avoiding external API calls for instance lists and consistently using NodeInfo for software detection, as suggested in the issue. The data/fedi_instances.json file will need to be updated periodically to keep the autocomplete list fresh.

This commit addresses issue #471 by changing how the "Share to Fediverse"
feature handles Fediverse instance data and software name detection.

Key changes:

1.  **Bundled Instance List:** The theme now uses a locally bundled
    list of Fediverse instances stored in `data/fedi_instances.json`
    for the autocomplete functionality in `fedishare.html`. This
    replaces the previous method of dynamically fetching this list
    from `api.fediverse.observer`. A fallback to a minimal hardcoded
    list is implemented if the JSON file is missing.

2.  **NodeInfo for Software Name:** The JavaScript logic in
    `fedishare.js` for determining the software of a Fediverse
    instance has been updated to primarily rely on the NodeInfo
    discovery protocol (`/.well-known/nodeinfo`). The previous check
    against data from Fediverse Observer has been removed. A
    fallback to "mastodon" is retained if NodeInfo discovery fails.

3.  **Removed Dynamic Fetching Code:** All Hugo templating and
    JavaScript code related to dynamically fetching instance lists
    and software names from Fediverse Observer has been removed.
    The site parameter `.Site.Params.fetchFediverseInstances` is
    no longer used by the theme.

These changes make the feature more reliable by avoiding external API
calls for instance lists and consistently using NodeInfo for software
detection, as suggested in the issue. The `data/fedi_instances.json`
file will need to be updated periodically to keep the autocomplete
list fresh.
@reuixiy reuixiy requested a review from Copilot June 7, 2025 05:02
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the “Share to Fediverse” feature to stop relying on live API calls and instead use a locally bundled list for autocomplete, and switches software detection to NodeInfo.

  • Load data/fedi_instances.json for domain autocomplete, with a minimal hardcoded fallback
  • Update getSoftwareName in fedishare.js to remove static mappings and use NodeInfo discovery only
  • Remove .Site.Params.fetchFediverseInstances and all Hugo/JS code for fetching from Fediverse Observer

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
layouts/partials/components/fedishare.html Replaced remote fetch logic with getJSON on a local JSON file and a hardcoded fallback slice; simplified <option> rendering
assets/js/fedishare.js Removed legacy loop that mapped <option data-project> attributes and now relies on NodeInfo only

Comment on lines +28 to +33
{{ $localInstances := getJSON "data/fedi_instances.json" }}
{{ if $localInstances }}
{{ $domains = $localInstances }}
{{ else }}
{{/* Fallback to a minimal hardcoded list if fedi_instances.json is not found or is empty */}}
{{ warnf "data/fedi_instances.json not found or empty. Falling back to minimal hardcoded instance list." }}
Copy link
Preview

Copilot AI Jun 7, 2025

Choose a reason for hiding this comment

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

Hugo's getJSON will error and interrupt the build if the file is missing or contains invalid JSON. Consider using a safe retrieval pattern (e.g., wrapping getJSON in a with block, using resources.Get and unmarshal with error handling, or the try function) to fall back gracefully.

Suggested change
{{ $localInstances := getJSON "data/fedi_instances.json" }}
{{ if $localInstances }}
{{ $domains = $localInstances }}
{{ else }}
{{/* Fallback to a minimal hardcoded list if fedi_instances.json is not found or is empty */}}
{{ warnf "data/fedi_instances.json not found or empty. Falling back to minimal hardcoded instance list." }}
{{ with getJSON "data/fedi_instances.json" }}
{{ $domains = . }}
{{ else }}
{{/* Fallback to a minimal hardcoded list if fedi_instances.json is not found or is empty */}}
{{ warnf "data/fedi_instances.json not found or invalid. Falling back to minimal hardcoded instance list." }}

Copilot uses AI. Check for mistakes.

{{ if and .softwarename (isset $projects .softwarename) (gt .score 90) (gt .active_users_monthly 10) -}}
<option data-project="{{ .softwarename }}">{{ .domain }}</option>
{{ end -}}
<option>{{ . }}</option>
Copy link
Preview

Copilot AI Jun 7, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider adding an explicit value attribute to the <option> tag (e.g., <option value="{{ . }}">{{ . }}</option>) to ensure consistent behavior across browsers and avoid relying on default value-text mapping.

Suggested change
<option>{{ . }}</option>
<option value="{{ . }}">{{ . }}</option>

Copilot uses AI. Check for mistakes.

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.

1 participant