1
0
mirror of https://github.com/kremalicious/astro-redirect-from.git synced 2024-11-21 17:37:02 +01:00

add scripts, release process

This commit is contained in:
Matthias Kretschmann 2023-09-22 13:17:25 +01:00
parent a98a07be8c
commit 7cdd34a805
Signed by: m
GPG Key ID: 606EEEF3C479A91F
8 changed files with 3537 additions and 41 deletions

7
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: npm
directory: '/'
schedule:
interval: weekly
time: '04:00'

46
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,46 @@
name: 'CI'
on:
push:
branches:
- main
tags:
- '**'
pull_request:
branches:
- '**'
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node: ['18', '20']
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- run: npm ci
- run: npm test
- run: npm run build
publish:
needs: test
if: success() && startsWith(github.ref, 'refs/tags')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

70
.github/workflows/codeql-analysis.yml vendored Normal file
View File

@ -0,0 +1,70 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: 'CodeQL'
on:
push:
branches: [main]
pull_request:
# The branches below must be a subset of the branches above
branches: [main]
schedule:
- cron: '24 22 * * 1'
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: ['javascript', 'typescript']
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support
steps:
- name: Checkout repository
uses: actions/checkout@v2
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1

View File

@ -44,17 +44,17 @@ Astro takes over from there, handling the redirects based on your site's build m
> For statically-generated sites with no adapter installed, this will produce a client redirect using a `<meta http-equiv="refresh">` tag and does not support status codes.
>
> When using SSR or with a static adapter in `output: static` mode, status codes are supported. Astro will serve redirected GET requests with a status of 301 and use a status of 308 for any other request method.
> When using SSR or with a static adapter in `output: static` mode, status codes are supported. Astro will serve redirected `GET` requests with a status of `301` and use a status of `308` for any other request method.
> [Astro Configuration Reference: redirects](https://docs.astro.build/en/reference/configuration-reference/#redirects)
The plugin is designed to work with various hosting integrations, where most of them generate further redirect files in the places they require so this plugin works in combination with them:
The plugin is designed to work with various Astro hosting integrations, most of them generate further redirect files in the places they require so this plugin works in combination with them:
- [ ] Netlify
- [ ] Vercel
- [ ] Cloudflare
- [ ] S3
Because Astro integrations are run in the order they are defined in Astro's `integrations` array, this plugin should come before any other integrations which make use of the `redirects` config.
Because Astro integrations are run in the order they are defined in the `integrations` array, this plugin should come before any other integrations which make use of the `redirects` config.
## Prerequisites
@ -147,8 +147,8 @@ function getSlugFromFilePath(filePath: string) {
let slug
// construct slug as full path from either:
// - file name, or
// - folder name if file name is index.md
// - folder name if file name is index.md, or
// - file name
if (parsedPath.base === 'index.md' || parsedPath.base === 'index.mdx') {
slug = `/${parsedPath.dir}`
} else {
@ -161,7 +161,7 @@ function getSlugFromFilePath(filePath: string) {
## Usage
In your Markdown file's YAML frontmatter, use the key `redirect_from` followed by a list.
In your Markdown file's frontmatter, use the key `redirect_from` followed by a list.
```yaml
---

3358
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,36 +1,68 @@
{
"name": "astro-redirect-from",
"version": "0.1.0",
"description": "🎯 Set redirect urls in your frontmatter within your Astro site's Markdown files. ",
"main": "index.js",
"description": "🎯 Set redirect urls in your frontmatter within your Astro site's Markdown files. Mimics the behavior of jekyll-redirect-from.",
"author": "Matthias Kretschmann <m@kretschmann.io>",
"license": "MIT",
"main": "dist/index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"build": "tsc",
"start": "tsc --watch",
"test": "npm run lint && npm run build",
"lint": "eslint src/**/*.js",
"format": "prettier --write 'src/**/*.{ts,js,json,md}'",
"changelog": "auto-changelog -p",
"release": "release-it --non-interactive",
"prepublishOnly": "npm run build"
},
"devDependencies": {
"@types/node": "^20.6.3",
"auto-changelog": "^2.4.0",
"eslint": "^8.49.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"prettier": "^3.0.3",
"release-it": "^16.1.5",
"typescript": "^5.2.2",
"vite": "^4.4.9"
},
"dependencies": {
"astro": "^3.1.2",
"fast-glob": "^3.3.1",
"gray-matter": "^4.0.3"
},
"peerDependencies": {
"astro": ">= 3"
},
"release-it": {
"hooks": {
"before:init": "npm test",
"after:bump": "npm run changelog"
},
"git": {
"tagName": "v${version}"
},
"github": {
"release": true
},
"npm": {
"publish": false
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/kremalicious/astro-redirect-from.git"
},
"keywords": [
"astro-integration"
"astro",
"astro-integration",
"redirect",
"redirect-from",
"jekyll-migration"
],
"author": "Matthias Kretschmann <m@kretschmann.io>",
"license": "MIT",
"bugs": {
"url": "https://github.com/kremalicious/astro-redirect-from/issues"
},
"homepage": "https://kremalicious.com/astro-redirect-from",
"type": "module",
"devDependencies": {
"@types/node": "^20.6.3",
"eslint": "^8.49.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"prettier": "^3.0.3",
"typescript": "^5.2.2"
},
"dependencies": {
"astro": "^3.1.2",
"fast-glob": "^3.3.1",
"gray-matter": "^4.0.3"
}
"homepage": "https://kremalicious.com/astro-redirect-from"
}

View File

@ -1,14 +1,13 @@
import path from 'node:path'
import fs from 'node:fs/promises'
import type { PathLike } from 'node:fs'
import { promises as fs, type PathLike } from 'node:fs'
export function getSlugFromFilePath(filePath: string) {
const parsedPath = path.parse(filePath)
let slug
// construct slug as full path from either:
// - file name, or
// - folder name if file name is index.md
// - folder name if file name is index.md, or
// - file name
if (parsedPath.base === 'index.md' || parsedPath.base === 'index.mdx') {
slug = `/${parsedPath.dir}`
} else {

View File

@ -1,9 +1,9 @@
{
"extends": "astro/tsconfigs/strict",
"include": ["src"],
"exclude": ["node_modules"],
"exclude": ["node_modules", "dist"],
"compilerOptions": {
"outDir": "./dist",
"typeRoots": ["node_modules/@types"]
"types": ["vite/client"]
}
}