Skip to content

Commit

Permalink
Modernize and bring up to latest plugin standards
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmayer committed Jul 9, 2024
1 parent 1b0624e commit 7806ecb
Show file tree
Hide file tree
Showing 12 changed files with 457 additions and 99 deletions.
27 changes: 27 additions & 0 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"template": "https://github.com/getpelican/cookiecutter-pelican-plugin",
"commit": "b4b9b4f83b624cfd7728a3f1527d272be28ee916",
"checkout": null,
"context": {
"cookiecutter": {
"plugin_name": "Dead Links",
"repo_name": "deadlinks",
"package_name": "deadlinks",
"distribution_name": "pelican-deadlinks",
"version": "0.0.0",
"description": "Pelican plugin to scan links and check their status codes",
"authors": "{name = \"Justin Mayer\", email = \"[email protected]\"}",
"keywords": "\"pelican\", \"plugin\", \"link\", \"checker\"",
"readme": "README.md",
"contributing": "CONTRIBUTING.md",
"license": "MIT License|MIT",
"repo_url": "https://github.com/pelican-plugins/deadlinks",
"dev_status": "5 - Production/Stable",
"tests_exist": false,
"python_version": ">=3.8.1,<4.0",
"pelican_version": ">=4.5",
"_template": "https://github.com/getpelican/cookiecutter-pelican-plugin"
}
},
"directory": null
}
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.py]
max_line_length = 88

[*.yml]
indent_size = 2
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: justinmayer
liberapay: pelican
68 changes: 68 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: build

on: [push, pull_request]

env:
PYTEST_ADDOPTS: "--color=yes"

permissions:
contents: read

jobs:
lint:
name: Lint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python & PDM
uses: pdm-project/setup-pdm@v4
with:
python-version: "3.10"

- name: Install dependencies
run: pdm install

- name: Run linters
run: pdm run invoke lint --diff

deploy:
name: Deploy
environment: Deployment
needs: [lint]
runs-on: ubuntu-latest
if: github.ref=='refs/heads/main' && github.event_name!='pull_request'

permissions:
contents: write
id-token: write

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Check release
id: check_release
run: |
python -m pip install autopub httpx
python -m pip install https://github.com/scikit-build/github-release/archive/master.zip
autopub check
- name: Publish
if: ${{ steps.check_release.outputs.autopub_release=='true' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
autopub prepare
autopub commit
autopub build
autopub githubrelease
- name: Upload package to PyPI
if: ${{ steps.check_release.outputs.autopub_release=='true' }}
uses: pypa/gh-action-pypi-publish@release/v1
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,6 @@ ENV/
*.swp
*.orig

# PDM
.pdm-python
pdm.lock
28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
ci:
autoupdate_schedule: quarterly

# See https://pre-commit.com/hooks.html for info on hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-case-conflict
- id: check-docstring-first
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: detect-private-key
- id: end-of-file-fixer
- id: forbid-new-submodules
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.1
hooks:
- id: ruff
- id: ruff-format
args: ["--check"]
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Contributing
============

Contributions are welcome and much appreciated. Every little bit helps. You can contribute by improving the documentation, adding missing features, and fixing bugs. You can also help out by reviewing and commenting on [existing issues][].

To start contributing to this plugin, review the [Contributing to Pelican][] documentation, beginning with the **Contributing Code** section.

[existing issues]: https://github.com/pelican-plugins/deadlinks/issues
[Contributing to Pelican]: https://docs.getpelican.com/en/latest/contribute.html
72 changes: 39 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,39 @@
# Dead Links
Dead Links: A Plugin for Pelican
================================

This plugin scans for links and checks status code of requested url.
For responses such as 403 or 404, the plugin adds a "disabled" class
to the anchor, extends anchor with a span label and dumps warning to
the logger.
[![Build Status](https://img.shields.io/github/actions/workflow/status/pelican-plugins/deadlinks/main.yml?branch=main)](https://github.com/pelican-plugins/deadlinks/actions)
[![PyPI Version](https://img.shields.io/pypi/v/pelican-deadlinks)](https://pypi.org/project/pelican-deadlinks/)
[![Downloads](https://img.shields.io/pypi/dm/pelican-deadlinks)](https://pypi.org/project/pelican-deadlinks/)
![License](https://img.shields.io/pypi/l/pelican-deadlinks?color=blue)

This Pelican plugin scans links and check their status codes. For responses such as 403 or 404, the plugin adds a `disabled` class to the anchor, extends the anchor with a `span` label, and prints a warning to the console logger.

# Requirements
Installation
------------

BeautifulSoup4, requests
This plugin can be installed via:

To install them using pip, type: `pip install bs4 requests`
python -m pip install pelican-deadlinks

# Installation
As long as you have not explicitly added a `PLUGINS` setting to your Pelican settings file, then the newly-installed plugin should be automatically detected and enabled. Otherwise, you must add `deadlinks` to your existing `PLUGINS` list. For more information, please see the [How to Use Plugins](https://docs.getpelican.com/en/latest/plugins.html#how-to-use-plugins) documentation.

Clone repository somewhere (let's assume destination is ./plugins/custom/deadlinks)
and edit configuration file:
Usage
-----

```python
PLUGINS_PATH = [
# [...]
'plugins/custom'
]
PLUGINS = [
# [...]
'deadlinks'
]
```

# Settings
To enable the dead link checker, set the `DEADLINKS_VALIDATION` option in your Pelican settings file to `True`. Alternatively, if you don’t want to validate links every time, you can selectively enable link validation at run-time via:

To enable dead link checker, set the `DEADLINK_VALIDATION` option in your
Pelican configuration file to True.
pelican content -e DEADLINKS_VALIDATION=true

Additionally following options might be changed:
Additionally, the following options can be changed:

```python
DEADLINK_OPTS = {
'archive': True,
'classes': ['custom-class1', 'disabled'],
'labels': True,
'timeout_duration_ms': 1000,
'timeout_is_error': False,
}
DEADLINKS_OPTIONS = {
"archive": True,
"classes": ["custom-class1", "disabled"],
"labels": True,
"timeout_duration_ms": 1000,
"timeout_is_error": False,
}
```

Options:
Expand All @@ -54,3 +45,18 @@ Options:
| `labels` | Insert bootstrap's label after the anchor element | False |
| `timeout_duration_ms` | Time in ms after which request is considered as timed out | 1000 |
| `timeout_is_error` | True/False. When enabled every time out is considered as dead link | False |

Contributing
------------

Contributions are welcome and much appreciated. Every little bit helps. You can contribute by improving the documentation, adding missing features, and fixing bugs. You can also help out by reviewing and commenting on [existing issues][].

To start contributing to this plugin, review the [Contributing to Pelican][] documentation, beginning with the **Contributing Code** section.

[existing issues]: https://github.com/pelican-plugins/deadlinks/issues
[Contributing to Pelican]: https://docs.getpelican.com/en/latest/contribute.html

License
-------

This project is licensed under the MIT license.
6 changes: 1 addition & 5 deletions pelican/plugins/deadlinks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
# -*- coding: utf8 -*-

from .deadlinks import *


from .deadlinks import * # noqa: F403,PGH004,RUF100
Loading

0 comments on commit 7806ecb

Please sign in to comment.