Skip to content

Commit

Permalink
Merge pull request #63 from iamvishnusankar/development
Browse files Browse the repository at this point in the history
Added support for custom config file
  • Loading branch information
iamvishnusankar committed Nov 12, 2020
2 parents 74e4b73 + ba2173d commit a390fb8
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 5 deletions.
27 changes: 27 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: iamvishnusankar
---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Additional context**
Add any other context about the problem here.
19 changes: 19 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: iamvishnusankar
---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ on:
push:
branches:
- master
# - development

pull_request:
branches:
- master
- development

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
node: ['14', '13', '12', '11', '10']
runs-on: ${{ matrix.platform }}
steps:
- name: Github Checkout
uses: actions/checkout@v2
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ Add next-sitemap as your postbuild script
}
```

Having `next-sitemap` command & `next-sitemap.js` file may result in file opening instead of building sitemaps in windows machines. [Please read more about the issue here.](https://github.com/iamvishnusankar/next-sitemap/issues/61#issuecomment-725999452)

As a solution to this, it is now possible to use a custom config file instead of `next-sitemap.js`. Just pass `--config <your-config-file>.js` to build command.

From now onwards:

- `next-sitemap` uses configuration from `next-sitemap.js`
- `next-sitemap --config <custom-config-file>.js` uses config from `<custom-config-file>.js`

## Splitting large sitemap into multiple files

Define the `sitemapSize` property in `next-sitemap.js` to split large sitemap into multiple files.
Expand Down
2 changes: 1 addition & 1 deletion azure-pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 1.2$(rev:.r)
name: 1.3$(rev:.r)
trigger:
branches:
include:
Expand Down
3 changes: 2 additions & 1 deletion packages/next-sitemap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"build:esnext": "tsc --module esnext --outDir dist/esnext"
},
"dependencies": {
"@corex/deepmerge": "^2.4.24"
"@corex/deepmerge": "^2.4.24",
"minimist": "^1.2.5"
}
}
11 changes: 9 additions & 2 deletions packages/next-sitemap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ import { loadManifest } from './manifest'
import { createUrlSet, generateUrl } from './url'
import { generateSitemap } from './sitemap'
import { toChunks } from './array'
import { resolveSitemapChunks, KNOWN_PATHS, getRuntimePaths } from './path'
import {
resolveSitemapChunks,
getRuntimePaths,
getConfigFilePath,
} from './path'
import { exportRobotsTxt } from './robots-txt'

// Get config file path
const configFilePath = getConfigFilePath()

// Load next-sitemap.js
let config = loadConfig(KNOWN_PATHS.CONFIG_FILE)
let config = loadConfig(configFilePath)

// Get runtime paths
const runtimePaths = getRuntimePaths(config)
Expand Down
16 changes: 16 additions & 0 deletions packages/next-sitemap/src/path/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
IRuntimePaths,
ISitemapFiled,
} from '../interface'
import minimist from 'minimist'
import fs from 'fs'

export const getPath = (...pathSegment: string[]): string => {
return path.resolve(process.cwd(), ...pathSegment)
Expand Down Expand Up @@ -38,6 +40,20 @@ export const getRuntimePaths = (config: IConfig): IRuntimePaths => {
}
}

/**
* @deprecated Use getConfigFilePath instead
*/
export const KNOWN_PATHS = {
CONFIG_FILE: getPath('next-sitemap.js'),
}

export const getConfigFilePath = () => {
const args = minimist(process.argv.slice(2))
const configPath = getPath(args.config || 'next-sitemap.js')

if (!fs.existsSync(configPath)) {
throw new Error(`${configPath} does not exist.`)
}

return configPath
}

0 comments on commit a390fb8

Please sign in to comment.