1313import java .time .LocalDate ;
1414import java .time .OffsetDateTime ;
1515import java .time .ZoneOffset ;
16- import java .time .format .DateTimeFormatter ;
1716import java .util .ArrayList ;
1817import java .util .Arrays ;
1918import java .util .Comparator ;
@@ -46,7 +45,6 @@ final class GenerateReadme {
4645 private static final Comparator <String > TEXT_ORDER =
4746 Comparator .comparing ((String value ) -> value .toLowerCase (Locale .ROOT ))
4847 .thenComparing (Comparator .naturalOrder ());
49- private static final DateTimeFormatter DISPLAY_DATE = DateTimeFormatter .ofPattern ("dd/MM/uuuu" );
5048
5149 public static void main (String [] args ) throws Exception {
5250 if (args .length == 0 ) {
@@ -74,10 +72,10 @@ public static void main(String[] args) throws Exception {
7472 private static void usage () {
7573 System .err .println ("""
7674 Usage:
77- java scripts/GenerateReadme.java check [source]
78- java scripts/GenerateReadme.java check-added <base-source> [source]
79- java scripts/GenerateReadme.java self-test
80- java scripts/GenerateReadme.java generate [source] [output] [cache] [--refresh-all] [--branch name]
75+ java .github/ scripts/GenerateReadme.java check [source]
76+ java .github/ scripts/GenerateReadme.java check-added <base-source> [source]
77+ java .github/ scripts/GenerateReadme.java self-test
78+ java .github/ scripts/GenerateReadme.java generate [source] [output] [cache] [--refresh-all] [--branch name]
8179 """ );
8280 }
8381
@@ -108,7 +106,7 @@ private static void generate(String[] args) throws Exception {
108106 var outputPath = Path .of (args .length > 2 ? args [2 ] : "README.md" );
109107 var cachePath = Path .of (args .length > 3 ? args [3 ] : ".cache/github-stats.tsv" );
110108 var refreshAll = false ;
111- var branch = System .getenv ().getOrDefault ("GITHUB_REF_NAME" , "master " );
109+ var branch = System .getenv ().getOrDefault ("GITHUB_REF_NAME" , "main " );
112110
113111 for (var i = 4 ; i < args .length ; i ++) {
114112 switch (args [i ]) {
@@ -522,27 +520,18 @@ private static void writeCache(Path path, StatsCache cache) throws IOException {
522520
523521 private static String render (Catalog source , StatsCache cache , LocalDate today , String branch ) {
524522 var out = new StringBuilder ();
525- out .append ("<!-- Generated from README_SOURCE.md by scripts/GenerateReadme.java. " )
523+ out .append ("<!-- Generated from README_SOURCE.md by .github/ scripts/GenerateReadme.java. " )
526524 .append ("Do not edit README.md directly. -->\n \n " )
527525 .append (source .title ()).append ("\n \n " )
528526 .append (source .tagline ()).append ("\n \n " )
529527 .append ("<sub>" ).append (projectCount (source )).append (" projects · " )
530528 .append (source .categories ().size ()).append (" categories · " )
531- .append (resourceCount (source )).append (" resources · " )
532- .append (DISPLAY_DATE .format (cache .refreshed ())).append ("</sub>\n \n " )
529+ .append (resourceCount (source )).append (" resources</sub>\n \n " )
533530 .append ("<sub>Activity: 🟢 pushed within 3 months · 🟠 pushed 3–12 months ago · " )
534531 .append ("🔴 no push for over 12 months</sub>\n \n " )
535532 .append ("<sub>License chips use GitHub SPDX metadata when available.</sub>\n \n " )
536533 .append ("<sub>Entries spanning several repositories combine their stars, use the most recent push for activity " )
537534 .append ("and show a license only when all repositories agree.</sub>\n \n " )
538- .append ("Browse a category below, or use your browser's find command to locate a project.\n \n " )
539- .append ("<details>\n " )
540- .append ("<summary><strong>Browse</strong></summary>\n \n " )
541- .append ("**Projects:** " );
542- appendNavigation (out , source .categories ().stream ().map (category -> category .name ).sorted (TEXT_ORDER ).toList ());
543- out .append ("\n \n **Resources:** " );
544- appendNavigation (out , source .resources ().stream ().map (resource -> resource .name ).toList ());
545- out .append ("\n \n </details>\n \n " )
546535 .append ("## Projects\n \n " );
547536
548537 source .categories ().stream ()
@@ -567,16 +556,6 @@ private static String render(Catalog source, StatsCache cache, LocalDate today,
567556 return out .toString ();
568557 }
569558
570- private static void appendNavigation (StringBuilder out , List <String > names ) {
571- for (var i = 0 ; i < names .size (); i ++) {
572- if (i > 0 ) {
573- out .append (" · " );
574- }
575- var name = names .get (i );
576- out .append ('[' ).append (name ).append ("](#" ).append (slug (name )).append (')' );
577- }
578- }
579-
580559 private static void renderCategory (
581560 StringBuilder out ,
582561 Category category ,
@@ -701,9 +680,6 @@ private static void validateRendered(
701680 0 , "Generated README contains the retired commercial badge" );
702681 require (!rendered .matches ("(?s).*<kbd>\\ d{2}/\\ d{2}/\\ d{4}</kbd>.*" ), 0 ,
703682 "Generated README contains a per-project date" );
704- require (countOccurrences (rendered , "](#" ) == source .categories ().size () + source .resources ().size (),
705- 0 , "Generated README contains an incomplete navigation index" );
706-
707683 for (var item : source .projects ()) {
708684 require (rendered .contains ("**[" + item .name () + "](" + item .url () + ")**" ), item .lineNumber (),
709685 "Generated README is missing project: " + item .name ());
@@ -850,14 +826,6 @@ private static String normalizeUrl(String url) {
850826 return url .toLowerCase (Locale .ROOT ).replaceAll ("/+$" , "" );
851827 }
852828
853- private static int countOccurrences (String value , String needle ) {
854- var count = 0 ;
855- for (var index = value .indexOf (needle ); index >= 0 ; index = value .indexOf (needle , index + 1 )) {
856- count ++;
857- }
858- return count ;
859- }
860-
861829 private static String knownLicense (String license ) {
862830 return license == null || license .isBlank ()
863831 || license .equals ("NOASSERTION" ) || license .equals ("OTHER" )
@@ -995,8 +963,6 @@ private static void selfTest() throws Exception {
995963 today ,
996964 "test"
997965 );
998- require (rendered .contains ("[Test](#test)" ) && rendered .contains ("[Links](#links)" ),
999- 0 , "Navigation rendering" );
1000966 require (rendered .contains ("Suggest a project or resource" ), 0 , "Contribution CTA" );
1001967 require (rendered .contains ("CC BY-SA 4.0" ) && rendered .contains ("[MIT](LICENSE-CODE)" ),
1002968 0 , "License footer" );
0 commit comments