Skip to content

Commit

Permalink
Merge pull request #21 from iamvishnusankar/development
Browse files Browse the repository at this point in the history
Additional configuration options
  • Loading branch information
iamvishnusankar committed Aug 23, 2020
2 parents 9389dbb + aa9a264 commit 0a4debd
Show file tree
Hide file tree
Showing 34 changed files with 439 additions and 308 deletions.
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,19 @@ Above is the minimal configuration to split a large sitemap. When the number of

## `next-sitemap.js` Options

| property | description | type |
| ----------------------------------- | ---------------------------------------------------------------------------------- | -------- |
| siteUrl | Base url of your website | string |
| changefreq (optional) | Change frequency. Default `daily` | string |
| priority (optional) | Priority. Default `0.7` | number |
| sitemapSize(optional) | Split large sitemap into multiple files by specifying sitemap size. Default `5000` | number |
| generateRobotsTxt | Generate a `robots.txt` file and list the generated sitemaps. Default `false` | boolean |
| robotsTxtOptions.policies | Policies for generating `robots.txt`. Default to `[{ userAgent: '*', allow: '/' }` | [] |
| robotsTxtOptions.additionalSitemaps | Options to add addition sitemap to `robots.txt` host entry | string[] |
| autoLastmod (optional) | Add `<lastmod/>` property. Default to `true` | true | |
| property | description | type |
| ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | -------- |
| siteUrl | Base url of your website | string |
| changefreq (optional) | Change frequency. Default `daily` | string |
| priority (optional) | Priority. Default `0.7` | number |
| sitemapSize(optional) | Split large sitemap into multiple files by specifying sitemap size. Default `5000` | number |
| generateRobotsTxt | Generate a `robots.txt` file and list the generated sitemaps. Default `false` | boolean |
| robotsTxtOptions.policies | Policies for generating `robots.txt`. Default to `[{ userAgent: '*', allow: '/' }` | [] |
| robotsTxtOptions.additionalSitemaps | Options to add addition sitemap to `robots.txt` host entry | string[] |
| autoLastmod (optional) | Add `<lastmod/>` property. Default to `true` | true | |
| exclude | Array of **relative** paths to exclude from listing on `sitemap.xml` or `sitemap-*.xml`. e.g.: `['/page-0', '/page-4']` | string[] |
| sourceDir | next.js build directory. Default `.next` | string |
| outDir | All the generated files will be exported to this directory. Default `public` | string |

## Full configuration

Expand All @@ -66,6 +69,7 @@ module.exports = {
priority: 0.7,
sitemapSize: 5000,
generateRobotsTxt: true,
exclude: ['/protected-page', '/awesome/secret-page'],
robotsTxtOptions: {
policies: [
{
Expand Down
112 changes: 112 additions & 0 deletions azure-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: 1.1$(rev:.r)
trigger:
branches:
include:
- master
pr:
branches:
include:
- master

pool:
vmImage: 'ubuntu-latest'
demands: npm

steps:
# Setup Node
- task: UseNode@1
displayName: Setup Node
inputs:
version: '14.x'

# Authenticate
- task: npmAuthenticate@0
displayName: NPM Auth
inputs:
workingFile: .npmrc
customEndpoint: 'NPM(Vishnu Sankar)'

# Install
- task: Bash@3
displayName: 'Install'
inputs:
targetType: 'inline'
script: 'yarn install'

# Build
- task: Bash@3
displayName: 'Build'
inputs:
targetType: 'inline'
script: 'yarn build'
failOnStderr: true

# Lint
- task: Bash@3
displayName: 'Lint'
inputs:
targetType: 'inline'
script: 'yarn lint'
failOnStderr: true

# Test
- task: Bash@3
displayName: 'Test'
inputs:
targetType: 'inline'
script: 'yarn test --ci'

# Set Version
- task: Bash@3
displayName: 'Set Version'
inputs:
targetType: 'inline'
script: 'yarn set-version'
failOnStderr: true

# Copy README
- task: Bash@3
displayName: 'Copy README'
inputs:
targetType: 'inline'
script: 'cp README.md packages/next-sitemap/README.md'
failOnStderr: true

# Test Result
- task: PublishTestResults@2
displayName: Publish Test Result
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: 'junit.xml'
failTaskOnFailedTests: true

# Coverage Result
- task: PublishCodeCoverageResults@1
displayName: Publish Coverage Result
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: 'coverage/cobertura-coverage.xml'
failIfCoverageEmpty: true

# Publish Packages
- task: Bash@3
displayName: 'Publish Packages'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
inputs:
targetType: 'inline'
script: 'yarn ywc publish'
failOnStderr: true

# Github Release
- task: GitHubRelease@1
displayName: Github Release
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
inputs:
gitHubConnection: 'iamvishnusankar'
repositoryName: '$(Build.Repository.Name)'
action: 'create'
target: '$(Build.SourceVersion)'
tagSource: 'userSpecifiedTag'
tag: 'v$(Build.BuildNumber)'
changeLogCompareToRelease: 'lastFullRelease'
changeLogType: 'commitBased'
62 changes: 0 additions & 62 deletions azure-pipeline/npm.yml

This file was deleted.

42 changes: 0 additions & 42 deletions azure-pipeline/pull-request.yml

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dev:docker": "docker-compose up -d",
"dev:test": "jest --watchAll",
"dev:tsc": "tsc --build --watch",
"build:ywc": "ywc clean build",
"build": "ywc clean build",
"build:tsc": "tsc --build",
"set-version": "ywc set-version",
"test": "jest --ci --coverage --verbose",
Expand Down
4 changes: 2 additions & 2 deletions packages/next-sitemap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
},
"scripts": {
"lint": "tsc --noEmit --declaration",
"build": "tsc && yarn build:cjs",
"build:cjs": "tsc --module commonjs --outDir dist/cjs"
"build": "tsc && yarn build:esnext",
"build:esnext": "tsc --module esnext --outDir dist/esnext"
},
"dependencies": {
"@corex/deepmerge": "^2.3.6"
Expand Down
25 changes: 0 additions & 25 deletions packages/next-sitemap/src/array/__snapshots__/index.test.ts.snap

This file was deleted.

16 changes: 12 additions & 4 deletions packages/next-sitemap/src/array/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import { toChunks, toArray } from './index'
import { toChunks, toArray, removeFromArray } from './index'

describe('next-sitemap/array', () => {
test('toChunks', () => {
const inputArray = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
const chunkSize = 3

const chunks = toChunks(inputArray, chunkSize)

expect(chunks).toMatchSnapshot()
expect(chunks.length).toBe(Math.ceil(inputArray.length / chunkSize))
expect(chunks).toStrictEqual([
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[9, 10],
])
})

test('toArray', () => {
expect(toArray('hello')).toStrictEqual(['hello'])
expect(toArray(['hello', 'world'])).toStrictEqual(['hello', 'world'])
})

test('removeFromArray', () => {
expect(removeFromArray([1, 2, 3], [2])).toStrictEqual([1, 3])
expect(removeFromArray([1, 2, 3], [2, 3, 4])).toStrictEqual([1])
})
})
9 changes: 9 additions & 0 deletions packages/next-sitemap/src/array/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@ export const toChunks = <T>(arr: T[], chunkSize: number): any => {
export const toArray = (inp: string | string[]): string[] => {
return typeof inp === 'string' ? [inp] : inp
}

/**
* Returns the difference between two arrays
* @param inputArr input array
* @param toRemoveArr array of elements to be removed
*/
export const removeFromArray = <T>(inputArr: T[], toRemoveArr: T[]): T[] => {
return inputArr.filter((x) => !toRemoveArr.includes(x))
}
15 changes: 11 additions & 4 deletions packages/next-sitemap/src/config/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { defaultConfig, withDefaultConfig } from '.'
import { IConfig } from '../interface'

describe('next-sitemap/config', () => {
test('defaultConfig', () => {
expect(defaultConfig).toStrictEqual({
rootDir: 'public',
expect(defaultConfig).toStrictEqual<Partial<IConfig>>({
sourceDir: '.next',
outDir: 'public',
priority: 0.7,
changefreq: 'daily',
sitemapSize: 5000,
autoLastmod: true,
exclude: [],
robotsTxtOptions: {
policies: [
{
Expand All @@ -22,8 +25,10 @@ describe('next-sitemap/config', () => {

test('withDefaultConfig', () => {
const myConfig = withDefaultConfig({
sourceDir: 'custom-source',
generateRobotsTxt: true,
sitemapSize: 50000,
exclude: ['1', '2'],
robotsTxtOptions: {
policies: [],
additionalSitemaps: [
Expand All @@ -33,13 +38,15 @@ describe('next-sitemap/config', () => {
},
})

expect(myConfig).toStrictEqual({
rootDir: 'public',
expect(myConfig).toStrictEqual<Partial<IConfig>>({
sourceDir: 'custom-source',
outDir: 'public',
priority: 0.7,
changefreq: 'daily',
sitemapSize: 50000,
autoLastmod: true,
generateRobotsTxt: true,
exclude: ['1', '2'],
robotsTxtOptions: {
policies: [],
additionalSitemaps: [
Expand Down

0 comments on commit 0a4debd

Please sign in to comment.