@@ -383,11 +383,80 @@ def _get_package_metadata(self) -> dict:
383383 # Family/group configuration for API organization
384384 metadata ["families" ] = tool_config .get ("families" , {})
385385
386+ # GitHub link style: "widget" (default) or "icon"
387+ metadata ["github_style" ] = tool_config .get ("github_style" , "widget" )
388+
386389 except Exception :
387390 pass
388391
389392 return metadata
390393
394+ def _update_navbar_github_link (
395+ self ,
396+ config : dict ,
397+ owner : str | None ,
398+ repo : str | None ,
399+ repo_url : str | None ,
400+ github_style : str ,
401+ ) -> None :
402+ """
403+ Update an existing navbar's GitHub link to use widget or icon style.
404+
405+ Parameters
406+ ----------
407+ config
408+ The Quarto configuration dictionary.
409+ owner
410+ GitHub repository owner.
411+ repo
412+ GitHub repository name.
413+ repo_url
414+ Full GitHub repository URL.
415+ github_style
416+ Either "widget" (with stats dropdown) or "icon" (simple link).
417+ """
418+ if not repo_url :
419+ return
420+
421+ navbar = config ["website" ]["navbar" ]
422+
423+ # Ensure right section exists
424+ if "right" not in navbar :
425+ navbar ["right" ] = []
426+
427+ # Build the new GitHub entry based on style
428+ if github_style == "widget" and owner and repo :
429+ new_gh_entry = {
430+ "text" : f'<div id="github-widget" data-owner="{ owner } " data-repo="{ repo } "></div>'
431+ }
432+ else :
433+ new_gh_entry = {"icon" : "github" , "href" : repo_url }
434+
435+ # Look for existing GitHub entry and replace it
436+ new_right = []
437+ found_github = False
438+
439+ for item in navbar ["right" ]:
440+ if isinstance (item , dict ):
441+ # Check for simple GitHub icon
442+ if item .get ("icon" ) == "github" :
443+ new_right .append (new_gh_entry )
444+ found_github = True
445+ # Check for existing widget
446+ elif "github-widget" in str (item .get ("text" , "" )):
447+ new_right .append (new_gh_entry )
448+ found_github = True
449+ else :
450+ new_right .append (item )
451+ else :
452+ new_right .append (item )
453+
454+ # If no GitHub entry was found, add one
455+ if not found_github :
456+ new_right .append (new_gh_entry )
457+
458+ navbar ["right" ] = new_right
459+
391460 def _get_github_repo_info (self ) -> tuple [str | None , str | None , str | None ]:
392461 """
393462 Extract GitHub repository information from pyproject.toml.
@@ -2399,7 +2468,12 @@ def _update_quarto_config(self) -> None:
23992468 if package_name :
24002469 config ["website" ]["title" ] = package_name .title ()
24012470
2402- # Add navbar with Home and API Reference links if not present
2471+ # Get GitHub info and style preference
2472+ owner , repo , repo_url = self ._get_github_repo_info ()
2473+ metadata = self ._get_package_metadata ()
2474+ github_style = metadata .get ("github_style" , "widget" ) # "widget" or "icon"
2475+
2476+ # Add or update navbar
24032477 if "navbar" not in config ["website" ]:
24042478 navbar_config = {
24052479 "left" : [
@@ -2408,24 +2482,22 @@ def _update_quarto_config(self) -> None:
24082482 ]
24092483 }
24102484
2411- # Add GitHub widget on the right if repository URL is available
2412- owner , repo , repo_url = self ._get_github_repo_info ()
2413-
2414- if owner and repo and repo_url :
2415- # Create GitHub widget HTML with data attributes
2485+ # Add GitHub link on the right if repository URL is available
2486+ if owner and repo and repo_url and github_style == "widget" :
24162487 gh_widget_html = (
24172488 f'<div id="github-widget" data-owner="{ owner } " data-repo="{ repo } "></div>'
24182489 )
24192490 navbar_config ["right" ] = [{"text" : gh_widget_html }]
24202491 elif repo_url :
2421- # Fallback to simple icon if we can't parse owner/repo
24222492 navbar_config ["right" ] = [{"icon" : "github" , "href" : repo_url }]
24232493
24242494 config ["website" ]["navbar" ] = navbar_config
2495+ else :
2496+ # Update existing navbar: upgrade icon to widget if configured
2497+ self ._update_navbar_github_link (config , owner , repo , repo_url , github_style )
24252498
2426- # Add GitHub widget script to page if not present
2427- owner , repo , _ = self ._get_github_repo_info ()
2428- if owner and repo :
2499+ # Add GitHub widget script to page if using widget style
2500+ if owner and repo and github_style == "widget" :
24292501 if "include-after-body" not in config ["format" ]["html" ]:
24302502 config ["format" ]["html" ]["include-after-body" ] = []
24312503 elif isinstance (config ["format" ]["html" ]["include-after-body" ], str ):
0 commit comments