html-convert/src/main/java/org/netbeans/tools/tutorials/AsciidocPostProcessor.java [92:231]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                switch (state) {
                    case BEFORE_CONTENT_SECTION:
                        if (isContentsHeader(line)) {
                            state = ContentSectionState.INSIDE_CONTENT_SECTION;
                            break;
                        }
                        output.println(line);
                        break;
                    case INSIDE_CONTENT_SECTION:
                        if (line.startsWith("* <")
                                || line.startsWith("* link:")) {
                            // Ignore bullet lists with cross references or external links
                        } else {
                            output.println(line);
                        }
                        if (line.startsWith("=")) {
                            state = ContentSectionState.AFTER_CONTENT_SECTION;
                        }
                        break;
                    case AFTER_CONTENT_SECTION:
                        output.println(line);
                        break;
                }
            } while (true);

        }

        Files.move(temporaryFile.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);

        if (title != null) {
            titles.put(file, title);
        }
    }

    static Map<File, String> removeContentSetcion(File dest) throws Exception {
        LOG.log(Level.INFO, "Removing \"Content\" section of files...");

        // Retrieve the list of asciidoc files
        List<File> asciidocFiles = Files.find(dest.toPath(), 999,
                (p, bfa) -> bfa.isRegularFile()).map(Path::toFile).filter((f) -> f.getName().endsWith(".asciidoc")).collect(Collectors.toList());

        // Remove the 'Contents' section and fetch titles
        HashMap<File, String> titles = new HashMap<>();
        for (File file : asciidocFiles) {
            cleanUpAndGetTitle(file, titles);
        }

        return titles;
    }

    /**
     * Generates index.asciidoc, index_ja.asciidoc, index_pt_BR.asciidoc, etc.,
     * in the nested directories, each index file has a list of links to
     * asciidoc documents in the directory. Asciidoc documents are sorted by
     * title, attending to the proper Locale collation rules.
     *
     * @param dest The destination directory.
     * @param titles
     * @throws IOException
     */
    static void generateIndexes(File dest, Map<File, String> titles) throws IOException {
        LOG.info("Generating index.asciidoc (and translations) on all directories...");
        /*
        Compute the list of directories under 'dest'
         */
        List<File> directories = Files.find(dest.toPath(), 999,
                (p, bfa) -> bfa.isDirectory()
        ).map((p) -> p.toFile()).collect(Collectors.toList());

        /*
        A filter that selects documents in english (i.e., without _ja, _pt_BR, etc. suffixes).
         */
        FileFilter englishTutorialsFilter = (f) -> f.isFile() && Language.getLanguage(f) == Language.DEFAULT;

        MustacheFactory factory = new DefaultMustacheFactory();
        Mustache indexMustache = factory.compile("org/netbeans/tools/tutorials/index-template.mustache");
        Mustache sectionMustache = factory.compile("org/netbeans/tools/tutorials/section-template.mustache");

        /*
        Iterate over all nexted directories...
         */
        for (File directory : directories) {
            if ("images".equals(directory.getName())) {
                continue;
            }

            HashMap<Language, List<File>> filesByLanguage = new HashMap<>();
            /*
            Compute the files in english
             */
            File[] tutorialsEnglish = directory.listFiles(englishTutorialsFilter);
            for (File english : tutorialsEnglish) {

                List<File> englishFiles = filesByLanguage.get(Language.DEFAULT);
                if (englishFiles == null) {
                    englishFiles = new ArrayList<File>();
                    filesByLanguage.put(Language.DEFAULT, englishFiles);
                }
                englishFiles.add(english);
                /*
                And retrieve the list of translations of the english file.
                 */
                HashMap<Language, File> translations = Language.getTranslations(english);
                for (Map.Entry<Language, File> translation : translations.entrySet()) {
                    List<File> languageFiles = filesByLanguage.get(translation.getKey());
                    if (languageFiles == null) {
                        languageFiles = new ArrayList<>();
                        filesByLanguage.put(translation.getKey(), languageFiles);
                    }
                    languageFiles.add(translation.getValue());
                }
            }

            for (Map.Entry<Language, List<File>> entry : filesByLanguage.entrySet()) {
                Language language = entry.getKey();
                if (language == Language.UNKNOWN) {
                    continue;
                }
                ResourceBundle bundle = ResourceBundle.getBundle("org.netbeans.tools.tutorials.TutorialsBundle", language.locale);
                String directoryTitle = bundle.getString( directory.getName() + ".title");
                if (directoryTitle == null) {
                    throw new IllegalArgumentException("Please add a title for directory '" + directory.getName() + "' in locale " + language.locale);
                }
                LocalizedTutorialSection section = new LocalizedTutorialSection(language, directoryTitle);
                section.addAll(entry.getValue());
                section.sort(titles);

                // Generate the index
                String name = "index" + language.extension;
                File output = new File(directory, name);
                try (Writer indexOutput = new OutputStreamWriter(new FileOutputStream(output), StandardCharsets.UTF_8)) {
                    indexMustache.execute(indexOutput, section);
                }
                
                // Also generate section.asciidoc (section_ja.asciidoc, etc.)
                // This will be in a sidebar for all tutorials in this section
                String sectionSidebarName = "section" + language.extension;
                File sectionSidebarFile = new File(directory, sectionSidebarName);
                try (Writer indexOutput = new OutputStreamWriter(new FileOutputStream(sectionSidebarFile), StandardCharsets.UTF_8)) {
                    sectionMustache.execute(indexOutput, section);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



tutorials-convert/src/main/java/org/netbeans/tools/tutorials/AsciidocPostProcessor.java [109:248]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                switch (state) {
                    case BEFORE_CONTENT_SECTION:
                        if (isContentsHeader(line)) {
                            state = ContentSectionState.INSIDE_CONTENT_SECTION;
                            break;
                        }
                        output.println(line);
                        break;
                    case INSIDE_CONTENT_SECTION:
                        if (line.startsWith("* <")
                                || line.startsWith("* link:")) {
                            // Ignore bullet lists with cross references or external links
                        } else {
                            output.println(line);
                        }
                        if (line.startsWith("=")) {
                            state = ContentSectionState.AFTER_CONTENT_SECTION;
                        }
                        break;
                    case AFTER_CONTENT_SECTION:
                        output.println(line);
                        break;
                }
            } while (true);

        }

        Files.move(temporaryFile.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);

        if (title != null) {
            titles.put(file, title);
        }
    }

    static Map<File, String> removeContentSetcion(File dest) throws Exception {
        LOG.log(Level.INFO, "Removing \"Content\" section of files...");

        // Retrieve the list of asciidoc files
        List<File> asciidocFiles = Files.find(dest.toPath(), 999,
                (p, bfa) -> bfa.isRegularFile()).map(Path::toFile).filter((f) -> f.getName().endsWith(".asciidoc")).collect(Collectors.toList());

        // Remove the 'Contents' section and fetch titles
        HashMap<File, String> titles = new HashMap<>();
        for (File file : asciidocFiles) {
            cleanUpAndGetTitle(file, titles);
        }

        return titles;
    }

    /**
     * Generates index.asciidoc, index_ja.asciidoc, index_pt_BR.asciidoc, etc.,
     * in the nested directories, each index file has a list of links to
     * asciidoc documents in the directory. Asciidoc documents are sorted by
     * title, attending to the proper Locale collation rules.
     *
     * @param dest The destination directory.
     * @param titles
     * @throws IOException
     */
    static void generateIndexes(File dest, Map<File, String> titles) throws IOException {
        LOG.info("Generating index.asciidoc (and translations) on all directories...");
        /*
        Compute the list of directories under 'dest'
         */
        List<File> directories = Files.find(dest.toPath(), 999,
                (p, bfa) -> bfa.isDirectory()
        ).map((p) -> p.toFile()).collect(Collectors.toList());

        /*
        A filter that selects documents in english (i.e., without _ja, _pt_BR, etc. suffixes).
         */
        FileFilter englishTutorialsFilter = (f) -> f.isFile() && Language.getLanguage(f) == Language.DEFAULT;

        MustacheFactory factory = new DefaultMustacheFactory();
        Mustache indexMustache = factory.compile("org/netbeans/tools/tutorials/index-template.mustache");
        Mustache sectionMustache = factory.compile("org/netbeans/tools/tutorials/section-template.mustache");

        /*
        Iterate over all nexted directories...
         */
        for (File directory : directories) {
            if ("images".equals(directory.getName())) {
                continue;
            }

            HashMap<Language, List<File>> filesByLanguage = new HashMap<>();
            /*
            Compute the files in english
             */
            File[] tutorialsEnglish = directory.listFiles(englishTutorialsFilter);
            for (File english : tutorialsEnglish) {

                List<File> englishFiles = filesByLanguage.get(Language.DEFAULT);
                if (englishFiles == null) {
                    englishFiles = new ArrayList<File>();
                    filesByLanguage.put(Language.DEFAULT, englishFiles);
                }
                englishFiles.add(english);
                /*
                And retrieve the list of translations of the english file.
                 */
                HashMap<Language, File> translations = Language.getTranslations(english);
                for (Map.Entry<Language, File> translation : translations.entrySet()) {
                    List<File> languageFiles = filesByLanguage.get(translation.getKey());
                    if (languageFiles == null) {
                        languageFiles = new ArrayList<>();
                        filesByLanguage.put(translation.getKey(), languageFiles);
                    }
                    languageFiles.add(translation.getValue());
                }
            }

            for (Map.Entry<Language, List<File>> entry : filesByLanguage.entrySet()) {
                Language language = entry.getKey();
                if (language == Language.UNKNOWN) {
                    continue;
                }
                ResourceBundle bundle = ResourceBundle.getBundle("org.netbeans.tools.tutorials.TutorialsBundle", language.locale);
                String directoryTitle = bundle.getString( directory.getName() + ".title");
                if (directoryTitle == null) {
                    throw new IllegalArgumentException("Please add a title for directory '" + directory.getName() + "' in locale " + language.locale);
                }
                LocalizedTutorialSection section = new LocalizedTutorialSection(language, directoryTitle);
                section.addAll(entry.getValue());
                section.sort(titles);

                // Generate the index
                String name = "index" + language.extension;
                File output = new File(directory, name);
                try (Writer indexOutput = new OutputStreamWriter(new FileOutputStream(output), StandardCharsets.UTF_8)) {
                    indexMustache.execute(indexOutput, section);
                }
                
                // Also generate section.asciidoc (section_ja.asciidoc, etc.)
                // This will be in a sidebar for all tutorials in this section
                String sectionSidebarName = "section" + language.extension;
                File sectionSidebarFile = new File(directory, sectionSidebarName);
                try (Writer indexOutput = new OutputStreamWriter(new FileOutputStream(sectionSidebarFile), StandardCharsets.UTF_8)) {
                    sectionMustache.execute(indexOutput, section);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



