Skip to content
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

feat: handle repositories starting with a dot #36

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,29 @@ Both methods provide the same functionality, so you can choose the one that fits

To ensure that the program functions correctly, please follow these conventions:

1. __Documentation folder structure__:
- The script will only parse the `docs/` folder located at the root level of the repository. This folder is used to import advanced documentation features, such as multi-page documentation, embedded images, and files.
### Repository name and structure

2. __File naming and sorting__:
- If a `docs/` folder is present, all files within it will be sorted and renamed by removing any prefix numbers. This ensures that files appear cleanly in the generated website. For example, `docs/01-get-started.md` will be renamed to `get-started.md`.
- The script will only parse the `docs/` folder located at the root level of the repository. This folder is used to import advanced documentation features, such as multi-page documentation, embedded images, and files.
- Repositories whose name starts with a dot are processed, but the dot will be removed.

3. __Handling the root readme file__:
- The `README.md` file located at the root of the repository will only be imported if there is no `./docs/01-readme.md` file present. This allows you to differentiate between the general README and the advanced documentation introduction page.
- For instance, you might use the README file for a table of contents that is not relevant in the context of the documentation website.
### File naming and sorting

4. __Link management__:
- Any inline link in the `./README.md` file that does not point to `./docs/**` will be replaced with the corresponding GitHub link.
- Similarly, any inline link in the `./docs/*.md` files that does not reference `./docs/**` will also be replaced with the appropriate GitHub link.
- If a `docs/` folder is present, all files within it will be sorted and renamed by removing any prefix numbers. This ensures that files appear cleanly in the generated website. For example, `docs/01-get-started.md` will be renamed to `get-started.md`.

5. __Project descriptions__:
- The project description displayed on the home page of the generated website is extracted from the GitHub repository's description.
### Handling the root readme file

- The `README.md` file located at the root of the repository will only be imported if there is no `./docs/01-readme.md` file present. This allows you to differentiate between the general README and the advanced documentation introduction page.
- For instance, you might use the README file for a table of contents that is not relevant in the context of the documentation website.

### Link management

- Any inline link in the `./README.md` file that does not point to `./docs/**` will be replaced with the corresponding GitHub link.
- Similarly, any inline link in the `./docs/*.md` files that does not reference `./docs/**` will also be replaced with the appropriate GitHub link.

### Project descriptions

- The project description displayed on the home page of the generated website is extracted from the GitHub repository's description.

---

By adhering to these rules, you can ensure that your documentation is processed correctly and that it aligns with the intended structure and functionality of the generated site.
32 changes: 20 additions & 12 deletions docs/02-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,29 @@

To ensure that the program functions correctly, please follow these conventions:

1. __Documentation folder structure__:
- The script will only parse the `docs/` folder located at the root level of the repository. This folder is used to import advanced documentation features, such as multi-page documentation, embedded images, and files.
## Repository name and structure

2. __File naming and sorting__:
- If a `docs/` folder is present, all files within it will be sorted and renamed by removing any prefix numbers. This ensures that files appear cleanly in the generated website. For example, `docs/01-get-started.md` will be renamed to `get-started.md`.
- The script will only parse the `docs/` folder located at the root level of the repository. This folder is used to import advanced documentation features, such as multi-page documentation, embedded images, and files.
- Repositories whose name starts with a dot are processed, but the dot will be removed.

3. __Handling the root readme file__:
- The `README.md` file located at the root of the repository will only be imported if there is no `./docs/01-readme.md` file present. This allows you to differentiate between the general README and the advanced documentation introduction page.
- For instance, you might use the README file for a table of contents that is not relevant in the context of the documentation website.
## File naming and sorting

4. __Link management__:
- Any inline link in the `./README.md` file that does not point to `./docs/**` will be replaced with the corresponding GitHub link.
- Similarly, any inline link in the `./docs/*.md` files that does not reference `./docs/**` will also be replaced with the appropriate GitHub link.
- If a `docs/` folder is present, all files within it will be sorted and renamed by removing any prefix numbers. This ensures that files appear cleanly in the generated website. For example, `docs/01-get-started.md` will be renamed to `get-started.md`.

5. __Project descriptions__:
- The project description displayed on the home page of the generated website is extracted from the GitHub repository's description.
## Handling the root readme file

- The `README.md` file located at the root of the repository will only be imported if there is no `./docs/01-readme.md` file present. This allows you to differentiate between the general README and the advanced documentation introduction page.
- For instance, you might use the README file for a table of contents that is not relevant in the context of the documentation website.

## Link management

- Any inline link in the `./README.md` file that does not point to `./docs/**` will be replaced with the corresponding GitHub link.
- Similarly, any inline link in the `./docs/*.md` files that does not reference `./docs/**` will also be replaced with the appropriate GitHub link.

## Project descriptions

- The project description displayed on the home page of the generated website is extracted from the GitHub repository's description.

---

By adhering to these rules, you can ensure that your documentation is processed correctly and that it aligns with the intended structure and functionality of the generated site.
25 changes: 24 additions & 1 deletion src/lib/fetch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import { cloneRepo, getInfos } from './git'

vi.mock('node:fs', () => ({ writeFileSync: vi.fn() }))
vi.mock('node:path', () => ({ resolve: vi.fn((...args) => args.join('/')) }))
vi.mock('../utils/functions.js', () => ({
vi.mock('../utils/functions.js', async importOriginal => ({
...(await importOriginal()),
checkHttpStatus: vi.fn(),
createDir: vi.fn(),
}))
Expand Down Expand Up @@ -147,6 +148,28 @@ describe('getDoc', () => {

expect(console.warn).toHaveBeenCalledWith(expect.stringContaining('No repository respect docpress rules.'))
})

it('should clone repositories starting with a dot', async () => {
const repos = [
{
name: '.repo3',
clone_url: 'https://github.com/testUser/.repo3',
fork: false,
private: false,
docpress: { projectPath: '/path/to/repo3', branch: 'main', includes: ['README.md'] },
},
] as unknown as EnhancedRepository[]

await getDoc(repos, ['.repo3'])

expect(cloneRepo).toHaveBeenCalledWith(
repos[0].name,
repos[0].clone_url,
repos[0].docpress.projectPath,
repos[0].docpress.branch,
repos[0].docpress.includes,
)
})
})

describe('enhanceRepositories', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { resolve } from 'node:path'
import { writeFileSync } from 'node:fs'
import type { GlobalOpts } from '../schemas/global.js'
import type { FetchOpts } from '../schemas/fetch.js'
import { checkHttpStatus, createDir } from '../utils/functions.js'
import { checkHttpStatus, createDir, prettify } from '../utils/functions.js'
import { DOCPRESS_DIR, DOCS_DIR, USER_INFOS, USER_REPOS_INFOS } from '../utils/const.js'
import { log } from '../utils/logger.js'
import { cloneRepo, getInfos } from './git.js'
Expand Down Expand Up @@ -48,7 +48,7 @@ export async function enhanceRepositories(repos: Awaited<ReturnType<typeof getIn
await Promise.all(
repos.map(async (repo) => {
const computedBranch = branch ?? repo.default_branch ?? 'main'
const projectPath = resolve(DOCS_DIR, repo.name)
const projectPath = resolve(DOCS_DIR, prettify(repo.name, { removeDot: true }))
const filtered = isRepoFiltered(repo, reposFilter)
let includes: string[] = []

Expand Down
4 changes: 2 additions & 2 deletions src/lib/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ export function transformDoc(repositories: EnhancedRepository[], user: ReturnTyp
return generateSidebarPages(repository.name, parse(filename).name, acc)
}, [])

sidebar.push(generateSidebarProject(repository.name, sidebarItems))
features.push(...generateFeatures(repository.name, repository.description || ''))
sidebar.push(generateSidebarProject(prettify(repository.name, { removeDot: true }), sidebarItems))
features.push(...generateFeatures(prettify(repository.name, { removeDot: true }), repository.description || ''))
}

log(` Generate index content.`, 'info')
Expand Down
1 change: 0 additions & 1 deletion src/schemas/schemas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ describe('configSchema', () => {
})
})

// foo
describe('fetchOptsSchema', () => {
it('should validate valid fetch options', () => {
const validData = {
Expand Down
5 changes: 5 additions & 0 deletions src/utils/functions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ describe('prettify', () => {
const result = prettify('', { mode: 'capitalize' })
expect(result).toBe('')
})

it('should remove the dot at the start of the string', () => {
const result = prettify('.hello-world', { removeDot: true })
expect(result).toBe('hello-world')
})
})

describe('createDir', () => {
Expand Down
5 changes: 5 additions & 0 deletions src/utils/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ interface PrettifyOpts {
mode?: 'capitalize' | 'uppercase' | 'lowercase'
replaceDash?: boolean
removeIdx?: boolean
removeDot?: boolean
}

export function prettify(s: string, opts: PrettifyOpts) {
let u: string = ''

if (s.startsWith('.') && opts?.removeDot) {
u = s.slice(1)
}

if (opts?.removeIdx) {
u = s.replace(/^\d{2}-/, '')
}
Expand Down
Loading