Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Commit 9a84133

Browse files
committed
Add a command to count docs pages
1 parent 5d0d9c9 commit 9a84133

File tree

28 files changed

+957
-13
lines changed

28 files changed

+957
-13
lines changed

audit-cli/README.md

Lines changed: 141 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ audit-cli
6363
│ └── usage
6464
├── compare # Compare files across versions
6565
│ └── file-contents
66-
└── count # Count code examples
67-
└── tested-examples
66+
└── count # Count code examples and documentation pages
67+
├── tested-examples
68+
└── pages
6869
```
6970

7071
### Extract Commands
@@ -731,6 +732,135 @@ This command helps writers and maintainers:
731732

732733
By default, prints a single integer (total count) for use in CI or scripting. With `--count-by-product`, displays a formatted table with product names and counts.
733734

735+
#### `count pages`
736+
737+
Count documentation pages (.txt files) in the MongoDB documentation monorepo.
738+
739+
This command navigates to the `content` directory and recursively counts all `.txt` files, which represent documentation pages that resolve to unique URLs. The command automatically excludes certain directories and file types that don't represent actual documentation pages.
740+
741+
**Use Cases:**
742+
743+
This command helps writers and maintainers:
744+
- Track the total number of documentation pages across the monorepo
745+
- Monitor documentation coverage by product/project
746+
- Identify projects with extensive or minimal documentation
747+
- Exclude auto-generated or deprecated content from counts
748+
- Count only current versions of versioned documentation
749+
- Compare page counts across different documentation versions
750+
751+
**Automatic Exclusions:**
752+
753+
The command automatically excludes:
754+
- Files in `code-examples` directories at the root of `content` or `source` (these contain plain text examples, not pages)
755+
- Files in the following directories at the root of `content`:
756+
- `404` - Error pages
757+
- `meta` - MongoDB Meta Documentation - style guide, tools, etc.
758+
- `table-of-contents` - Navigation files
759+
- All non-`.txt` files (configuration files, YAML, etc.)
760+
761+
**Basic Usage:**
762+
763+
```bash
764+
# Get total count of all documentation pages
765+
./audit-cli count pages /path/to/docs-monorepo
766+
767+
# Count pages for a specific project
768+
./audit-cli count pages /path/to/docs-monorepo --for-project manual
769+
770+
# Show counts broken down by project
771+
./audit-cli count pages /path/to/docs-monorepo --count-by-project
772+
773+
# Exclude specific directories from counting
774+
./audit-cli count pages /path/to/docs-monorepo --exclude-dirs api-reference,generated
775+
776+
# Count only current versions (for versioned projects)
777+
./audit-cli count pages /path/to/docs-monorepo --current-only
778+
779+
# Show counts by project and version
780+
./audit-cli count pages /path/to/docs-monorepo --by-version
781+
782+
# Combine flags: count pages for a specific project, excluding certain directories
783+
./audit-cli count pages /path/to/docs-monorepo --for-project atlas --exclude-dirs deprecated
784+
```
785+
786+
**Flags:**
787+
788+
- `--for-project <project>` - Only count pages for a specific project (directory name under `content/`)
789+
- `--count-by-project` - Display counts for each project in a formatted table
790+
- `--exclude-dirs <dirs>` - Comma-separated list of directory names to exclude from counting (e.g., `deprecated,archive`)
791+
- `--current-only` - Only count pages in the current version (for versioned projects, counts only `current` or `manual` version directories; for non-versioned projects, counts all pages)
792+
- `--by-version` - Display counts grouped by project and version (shows version breakdown for versioned projects; non-versioned projects show as "(no version)")
793+
794+
**Output:**
795+
796+
By default, prints a single integer (total count) for use in CI or scripting. With `--count-by-project`, displays a formatted table with project names and counts. With `--by-version`, displays a hierarchical breakdown by project and version.
797+
798+
**Versioned Documentation:**
799+
800+
Some MongoDB documentation projects contain multiple versions, represented as distinct directories between the project directory and the `source` directory:
801+
- **Versioned project structure**: `content/{project}/{version}/source/...`
802+
- **Non-versioned project structure**: `content/{project}/source/...`
803+
804+
Version directory names follow these patterns:
805+
- `current` or `manual` - The current/latest version
806+
- `upcoming` - Pre-release version
807+
- `v{number}` - Specific version (e.g., `v8.0`, `v7.0`)
808+
809+
The `--current-only` flag counts only files in the current version directory (`current` or `manual`) for versioned projects, while counting all files for non-versioned projects.
810+
811+
The `--by-version` flag shows a breakdown of page counts for each version within each project.
812+
813+
**Note:** The `--current-only` and `--by-version` flags are mutually exclusive.
814+
815+
**Examples:**
816+
817+
```bash
818+
# Quick count for CI/CD
819+
TOTAL_PAGES=$(./audit-cli count pages ~/docs-monorepo)
820+
echo "Total documentation pages: $TOTAL_PAGES"
821+
822+
# Detailed breakdown by project
823+
./audit-cli count pages ~/docs-monorepo --count-by-project
824+
# Output:
825+
# Page Counts by Project:
826+
#
827+
# app-services 245
828+
# atlas 512
829+
# manual 1024
830+
# ...
831+
#
832+
# Total: 2891
833+
834+
# Count only Atlas pages
835+
./audit-cli count pages ~/docs-monorepo --for-project atlas
836+
# Output: 512
837+
838+
# Exclude deprecated content
839+
./audit-cli count pages ~/docs-monorepo --exclude-dirs deprecated,archive --count-by-project
840+
841+
# Count only current versions
842+
./audit-cli count pages ~/docs-monorepo --current-only
843+
# Output: 1245 (only counts current/manual versions)
844+
845+
# Show breakdown by version
846+
./audit-cli count pages ~/docs-monorepo --by-version
847+
# Output:
848+
# Project: drivers
849+
# manual 150
850+
# upcoming 145
851+
# v8.0 140
852+
# v7.0 135
853+
#
854+
# Project: atlas
855+
# (no version) 200
856+
#
857+
# Total: 770
858+
859+
# Count current version for a specific project
860+
./audit-cli count pages ~/docs-monorepo --for-project drivers --current-only
861+
# Output: 150
862+
```
863+
734864
## Development
735865

736866
### Project Structure
@@ -780,9 +910,15 @@ audit-cli/
780910
│ │ └── version_resolver.go # Version path resolution
781911
│ └── count/ # Count parent command
782912
│ ├── count.go # Parent command definition
783-
│ └── tested-examples/ # Tested examples counting subcommand
784-
│ ├── tested_examples.go # Command logic
785-
│ ├── tested_examples_test.go # Tests
913+
│ ├── tested-examples/ # Tested examples counting subcommand
914+
│ │ ├── tested_examples.go # Command logic
915+
│ │ ├── tested_examples_test.go # Tests
916+
│ │ ├── counter.go # Counting logic
917+
│ │ ├── output.go # Output formatting
918+
│ │ └── types.go # Type definitions
919+
│ └── pages/ # Pages counting subcommand
920+
│ ├── pages.go # Command logic
921+
│ ├── pages_test.go # Tests
786922
│ ├── counter.go # Counting logic
787923
│ ├── output.go # Output formatting
788924
│ └── types.go # Type definitions

audit-cli/commands/count/count.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
1-
// Package count provides the parent command for counting code examples.
1+
// Package count provides the parent command for counting code examples and documentation pages.
22
//
33
// This package serves as the parent command for various counting operations.
44
// Currently supports:
55
// - tested-examples: Count tested code examples in the MongoDB documentation monorepo
6-
//
7-
// Future subcommands could include counting other types of content.
6+
// - pages: Count documentation pages (.txt files) in the MongoDB documentation monorepo
87
package count
98

109
import (
10+
"github.com/mongodb/code-example-tooling/audit-cli/commands/count/pages"
1111
"github.com/mongodb/code-example-tooling/audit-cli/commands/count/tested-examples"
1212
"github.com/spf13/cobra"
1313
)
1414

1515
// NewCountCommand creates the count parent command.
1616
//
17-
// This command serves as a parent for various counting operations on code examples.
17+
// This command serves as a parent for various counting operations on code examples and documentation pages.
1818
// It doesn't perform any operations itself but provides a namespace for subcommands.
1919
func NewCountCommand() *cobra.Command {
2020
cmd := &cobra.Command{
2121
Use: "count",
22-
Short: "Count code examples",
23-
Long: `Count various types of code examples in the MongoDB documentation.
22+
Short: "Count code examples and documentation pages",
23+
Long: `Count various types of content in the MongoDB documentation.
2424
25-
Currently supports counting tested code examples in the documentation monorepo.
26-
Future subcommands may support counting other types of content.`,
25+
Currently supports:
26+
- tested-examples: Count tested code examples in the documentation monorepo
27+
- pages: Count documentation pages (.txt files) in the documentation monorepo`,
2728
}
2829

2930
// Add subcommands
3031
cmd.AddCommand(tested_examples.NewTestedExamplesCommand())
32+
cmd.AddCommand(pages.NewPagesCommand())
3133

3234
return cmd
3335
}

0 commit comments

Comments
 (0)