Skip to content
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
28 changes: 28 additions & 0 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"template": "https://github.com/getpelican/cookiecutter-pelican-plugin",
"commit": "8a4f543e999c7a2b4ab49c724bf84ff4192f4c94",
"checkout": null,
"context": {
"cookiecutter": {
"plugin_name": "SEO",
"repo_name": "seo",
"package_name": "seo",
"distribution_name": "pelican-seo",
"version": "1.2.2",
"description": "Pelican plugin to improve search engine optimization (SEO)",
"authors": "{name = \"Maëva Brunelles\", email = \"contact@tremacorp.fr\"}, {name = \"Justin Mayer\", email = \"entroP@gmail.com\"}",
"keywords": "\"pelican\", \"plugin\", \"seo\", \"search\", \"optimization\"",
"readme": "README.md",
"contributing": "CONTRIBUTING.md",
"license": "GNU Affero General Public License v3|AGPL-3.0",
"repo_url": "https://github.com/pelican-plugins/seo",
"dev_status": "5 - Production/Stable",
"tests_exist": true,
"python_version": "~=3.9",
"pelican_version": ">=4.5",
"_template": "https://github.com/getpelican/cookiecutter-pelican-plugin",
"_commit": "f51b3c4a5160fc8f36cff3baf9da7e2b5f59e8d7"
}
},
"directory": null
}
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
110 changes: 51 additions & 59 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,103 +5,95 @@ on: [push, pull_request]
env:
PYTEST_ADDOPTS: "--color=yes"

permissions:
contents: read

jobs:
test:
name: Test - ${{ matrix.python-version }}
name: Test - Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Set up Pip cache
uses: actions/cache@v2
id: pip-cache
- uses: actions/checkout@v4
with:
path: ~/.cache/pip
key: pip-${{ hashFiles('**/pyproject.toml') }}
- name: Upgrade Pip
run: python -m pip install --upgrade pip
- name: Install Poetry
run: python -m pip install poetry
- name: Set up Poetry cache
uses: actions/cache@v2
id: poetry-cache
persist-credentials: false

- name: Set up Python ${{ matrix.python-version }} & PDM
uses: pdm-project/setup-pdm@v4
with:
path: ~/.cache/pypoetry/virtualenvs
key: poetry-${{ hashFiles('**/poetry.lock') }}
python-version: ${{ matrix.python-version }}
cache: true
cache-dependency-path: ./pyproject.toml

- name: Install dependencies
run: |
poetry run pip install --upgrade pip
poetry install
- name: Run tests
run: poetry run invoke tests
run: pdm install

- name: Run tests
run: pdm run invoke tests

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

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
persist-credentials: false

- name: Validate links in Markdown files
uses: JustinBeckwith/linkinator-action@v1
with:
retry: true
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.7
- name: Set Poetry cache
uses: actions/cache@v2
id: poetry-cache

- name: Set up Python & PDM
uses: pdm-project/setup-pdm@v4
with:
path: ~/.cache/pypoetry/virtualenvs
key: poetry-${{ hashFiles('**/poetry.lock') }}
- name: Upgrade Pip
run: python -m pip install --upgrade pip
- name: Install Poetry
run: python -m pip install poetry
python-version: "3.10"

- name: Install dependencies
run: |
poetry run pip install --upgrade pip
poetry install
- name: Run linters
run: poetry run invoke lint
run: pdm install

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

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

permissions:
contents: write
id-token: write

steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
- uses: actions/checkout@v4

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

- name: Check release
id: check_release
run: |
python -m pip install --upgrade pip
python -m pip install poetry githubrelease httpx==0.16.1 autopub
echo "##[set-output name=release;]$(autopub check)"
python -m pip install autopub[github]
autopub check

- name: Publish
if: ${{ steps.check_release.outputs.release=='' }}
if: ${{ steps.check_release.outputs.autopub_release=='true' }}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git remote set-url origin https://$GITHUB_TOKEN@github.com/${{ github.repository }}
autopub prepare
poetry build
autopub commit
autopub build
autopub githubrelease
poetry publish -u __token__ -p $PYPI_PASSWORD

- name: Upload package to PyPI
if: ${{ steps.check_release.outputs.autopub_release=='true' }}
uses: pypa/gh-action-pypi-publish@release/v1
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode/
*__pycache__
poetry.lock
.pdm-python
pdm.lock
28 changes: 7 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ci:
# See https://pre-commit.com/hooks.html for info on hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-ast
Expand All @@ -20,25 +20,11 @@ repos:
- id: forbid-new-submodules
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 23.7.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.1
hooks:
- id: black
- id: ruff
- id: ruff-format
args: ["--check"]

- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- id: flake8
args: [--max-line-length=88]
language_version: python3

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/asottile/pyupgrade
rev: v3.9.0
hooks:
- id: pyupgrade
args: [--py38-plus]
exclude: "tests/"
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![Build Status](https://img.shields.io/github/actions/workflow/status/pelican-plugins/seo/main.yml?branch=main)](https://github.com/pelican-plugins/seo/actions)
[![PyPI Version](https://img.shields.io/pypi/v/pelican-seo)](https://pypi.org/project/pelican-seo/)
[![Downloads](https://img.shields.io/pypi/dm/pelican-seo)](https://pypi.org/project/pelican-seo/)
![License](https://img.shields.io/pypi/l/pelican-seo?color=blue)

This plugin helps you improve your Pelican site SEO (Search Engine Optimization) to reach the top positions on search engines. To see what this SEO plugin can do for you, visit the [Usage](#usage) section.
Expand Down Expand Up @@ -31,6 +32,8 @@ This plugin can be installed via:

python -m pip install pelican-seo

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 `seo` 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.

## Requirements

The above installation step should automatically install Beautiful Soup 4, which the SEO plugin requires. The following command will manually install this dependency:
Expand Down Expand Up @@ -314,3 +317,8 @@ To start contributing to this plugin, review the [Contributing to Pelican][] doc

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

License
-------

This project is licensed under the AGPL-3.0 license.
2 changes: 1 addition & 1 deletion pelican/plugins/seo/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .seo import * # NOQA
from .seo import * # noqa: F403,PGH004,RUF100
8 changes: 5 additions & 3 deletions pelican/plugins/seo/seo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


def plugin_initializer(settings):
"""Raises if SITEURL parameter is not set in Pelican settings"""
"""Raise if SITEURL parameter is not set in Pelican settings."""

if not settings.settings.get("SITEURL"):
raise Exception(
Expand All @@ -37,7 +37,7 @@ def plugin_initializer(settings):


def get_plugin_settings(context):
"""Get settings in the Pelican configuration file from the given context
"""Get settings in the Pelican configuration file from the given context.

.. note:: Pelican's settings take precedence over the plugin's default settings.

Expand All @@ -58,7 +58,8 @@ def get_plugin_settings(context):
"""

def _get_seo_variables(settings):
"""Get variables starting with 'SEO_' & values in the given dictionary
"""Get variables starting with 'SEO_' & values in the given dictionary.

:rtype: <dict>
"""
return {
Expand Down Expand Up @@ -173,6 +174,7 @@ def run_html_enhancer(path, context):


def register():
"""Register the plugin."""

signals.initialized.connect(plugin_initializer)

Expand Down
20 changes: 7 additions & 13 deletions pelican/plugins/seo/seo_enhancer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Improve SEO technical for each article and page : HTML code and robots.txt file. """
"""Improve SEO technical for each article and page : HTML code and robots.txt file."""

import json
import logging
Expand All @@ -13,9 +13,7 @@


class SEOEnhancer:
"""
Improve SEO technical for each article and page : HTML code and robots.txt file.
"""
"""Improve SEO for each article and page : HTML code and robots.txt file."""

def launch_html_enhancer(
self, file, output_path, path, open_graph=False, twitter_cards=False
Expand Down Expand Up @@ -46,9 +44,9 @@ def launch_html_enhancer(
html_enhancements["open_graph"] = html_enhancer.open_graph.create_tags()

if twitter_cards:
html_enhancements[
"twitter_cards"
] = html_enhancer.twitter_cards.create_tags()
html_enhancements["twitter_cards"] = (
html_enhancer.twitter_cards.create_tags()
)

return html_enhancements

Expand All @@ -67,9 +65,7 @@ def populate_robots(self, document):
}

def generate_robots(self, rules, output_path):
"""
Create robots.txt file, with noindex and disallow rules for each document URL.
"""
"""Create robots.txt, with noindex and disallow rules for each document URL."""
if not os.path.isdir(output_path):
os.mkdir(output_path)

Expand All @@ -86,9 +82,7 @@ def generate_robots(self, rules, output_path):
logger.info("SEO plugin - SEO Enhancement: robots.txt file created")

def add_html_to_file(self, enhancements, path):
"""
Open HTML file, add HTML enhancements with bs4 and create the new HTML files.
"""
"""Open HTML file, add enhancements with bs4 and create the new HTML files."""

with open(path, encoding="utf8") as html_file:
html_content = html_file.read()
Expand Down
6 changes: 3 additions & 3 deletions pelican/plugins/seo/seo_enhancer/html_enhancer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" HTML Enhancer : get instances of HTML enhancements. """
"""HTML Enhancer : get instances of HTML enhancements."""

from pelican.contents import Article, Page

Expand All @@ -19,7 +19,7 @@ def __init__(self, file, output_path, path, open_graph=False, twitter_cards=Fals
elif isinstance(file, Page):
_file_type = "page"

_settings = getattr(file, "settings")
_settings = file.settings
_author = getattr(file, "author", None)
_date = getattr(file, "date", None)
_title = getattr(file, "title", None)
Expand Down Expand Up @@ -48,7 +48,7 @@ def __init__(self, file, output_path, path, open_graph=False, twitter_cards=Fals
)
else:
save_as = _metadata.get("save_as")
_fileurl = save_as if save_as else getattr(file, "url")
_fileurl = save_as if save_as else file.url
self.canonical_link = CanonicalURLCreator(
siteurl=_settings.get("SITEURL"),
fileurl=_fileurl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def _convert_date(self, date):
return date_time.strftime("%Y-%m-%d %H:%M")

def create_schema(self):
"""
Create Article schema.
"""Create Article schema.

Schema : {
"@context": "https://schema.org",
"@type": "Article",
Expand Down
Loading
Loading