Compare commits

..

No commits in common. "main" and "1.1.0" have entirely different histories.

12 changed files with 167 additions and 210 deletions

2
.github/FUNDING.yml vendored
View file

@ -1,2 +1,2 @@
github: justinmayer custom: https://donate.getpelican.com
liberapay: pelican liberapay: pelican

View file

@ -7,89 +7,102 @@ env:
jobs: jobs:
test: test:
name: Test - Python ${{ matrix.python-version }} name: Test - ${{ matrix.python-version }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] python-version: ["3.8", "3.9"]
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
- name: Set up Python ${{ matrix.python-version }} & PDM uses: actions/setup-python@v4
uses: pdm-project/setup-pdm@v4
with: with:
python-version: ${{ matrix.python-version }} python-version: ${{ matrix.python-version }}
cache: true - name: Set up Pip cache
cache-dependency-path: ./pyproject.toml uses: actions/cache@v3
id: pip-cache
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@v3
id: poetry-cache
with:
path: ~/.cache/pypoetry/virtualenvs
key: poetry-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies - name: Install dependencies
run: pdm install run: |
poetry run pip install --upgrade pip
poetry install
- name: Run tests - name: Run tests
run: pdm run invoke tests run: poetry run invoke tests
lint: lint:
name: Lint name: Lint
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v3
- name: Validate links in Markdown files - name: Validate links in Markdown files
uses: JustinBeckwith/linkinator-action@v1 uses: JustinBeckwith/linkinator-action@v1
with: with:
retry: true retry: true
- name: Set up Python
- name: Set up Python & PDM uses: actions/setup-python@v4
uses: pdm-project/setup-pdm@v4
with: with:
python-version: "3.10" python-version: "3.9"
- name: Set Poetry cache
uses: actions/cache@v3
id: poetry-cache
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
- name: Install dependencies - name: Install dependencies
run: pdm install run: |
poetry run pip install --upgrade pip
poetry install
- name: Run linters - name: Run linters
run: pdm run invoke lint --diff run: poetry run invoke lint
deploy: deploy:
name: Deploy name: Deploy
environment: Deployment environment: Deployment
needs: [test, lint] needs: [test, lint]
runs-on: ubuntu-latest 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: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with: with:
token: ${{ secrets.GH_TOKEN }} python-version: "3.9"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Check release - name: Check release
id: check_release id: check_release
run: | run: |
python -m pip install autopub httpx python -m pip install --upgrade pip
python -m pip install https://github.com/scikit-build/github-release/archive/master.zip python -m pip install poetry githubrelease httpx==0.16.1 autopub
autopub check echo "##[set-output name=release;]$(autopub check)"
- name: Publish - name: Publish
if: ${{ steps.check_release.outputs.autopub_release=='true' }} if: ${{ steps.check_release.outputs.release=='' }}
env: env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: | run: |
git remote set-url origin https://$GITHUB_TOKEN@github.com/${{ github.repository }}
autopub prepare autopub prepare
poetry build
autopub commit autopub commit
autopub build
autopub githubrelease 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
.gitignore vendored
View file

@ -1,2 +1 @@
.pdm-python poetry.lock
pdm.lock

View file

@ -5,12 +5,11 @@ ci:
# See https://pre-commit.com/hooks.html for info on hooks # See https://pre-commit.com/hooks.html for info on hooks
repos: repos:
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0 rev: v4.4.0
hooks: hooks:
- id: check-added-large-files - id: check-added-large-files
- id: check-ast - id: check-ast
- id: check-case-conflict - id: check-case-conflict
- id: check-docstring-first
- id: check-merge-conflict - id: check-merge-conflict
- id: check-toml - id: check-toml
- id: check-yaml - id: check-yaml
@ -20,9 +19,19 @@ repos:
- id: forbid-new-submodules - id: forbid-new-submodules
- id: trailing-whitespace - id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit - repo: https://github.com/psf/black
rev: v0.5.0 rev: 23.3.0
hooks: hooks:
- id: ruff - id: black
- id: ruff-format
args: ["--check"] - repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
args: [--max-line-length=88]
language_version: python3
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort

View file

@ -1,22 +1,6 @@
CHANGELOG CHANGELOG
========= =========
1.2.1 - 2025-03-23
------------------
Add title to Bluesky
Contributed by [Daniel Lemos](https://github.com/xspager) via [PR #34](https://github.com/pelican-plugins/share-post/pull/34/)
1.2.0 - 2025-01-29
------------------
Add Bluesky support
Contributed by [Leonardo Giordani](https://github.com/lgiordani) via [PR #33](https://github.com/pelican-plugins/share-post/pull/33/)
1.1.0 - 2023-08-31 1.1.0 - 2023-08-31
------------------ ------------------

View file

@ -2,7 +2,6 @@
[![Build Status](https://img.shields.io/github/actions/workflow/status/pelican-plugins/share-post/main.yml?branch=main)](https://github.com/pelican-plugins/share-post/actions) [![Build Status](https://img.shields.io/github/actions/workflow/status/pelican-plugins/share-post/main.yml?branch=main)](https://github.com/pelican-plugins/share-post/actions)
[![PyPI Version](https://img.shields.io/pypi/v/pelican-share-post)](https://pypi.org/project/pelican-share-post/) [![PyPI Version](https://img.shields.io/pypi/v/pelican-share-post)](https://pypi.org/project/pelican-share-post/)
[![Downloads](https://img.shields.io/pypi/dm/pelican-share-post)](https://pypi.org/project/pelican-share-post/)
![License](https://img.shields.io/pypi/l/pelican-share-post?color=blue) ![License](https://img.shields.io/pypi/l/pelican-share-post?color=blue)
Share Post is a Pelican plugin that creates share links in articles that allow site visitors to share the current article with others in a privacy-friendly manner. Share Post is a Pelican plugin that creates share links in articles that allow site visitors to share the current article with others in a privacy-friendly manner.
@ -19,8 +18,6 @@ This plugin can be installed via:
python -m pip install pelican-share-post python -m pip install pelican-share-post
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 `share_post` 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.
Usage Usage
----- -----
@ -36,7 +33,6 @@ article.share_post = {
"mastodon": "<URL>", "mastodon": "<URL>",
"reddit": "<URL>", "reddit": "<URL>",
"twitter": "<URL>", "twitter": "<URL>",
"bluesky": "<URL>",
} }
``` ```
@ -57,13 +53,11 @@ You can then access those variables in your template. For example:
<a href="{{article.share_post['linkedin']}}" title="Share on LinkedIn">LinkedIn</a> <a href="{{article.share_post['linkedin']}}" title="Share on LinkedIn">LinkedIn</a>
<a href="{{article.share_post['mastodon']}}" title="Share on Mastodon">Mastodon</a> <a href="{{article.share_post['mastodon]}}" title="Share on Mastodon">Mastodon</a>
<a href="{{article.share_post['reddit']}}" title="Share via Reddit">Reddit</a> <a href="{{article.share_post['reddit']}}" title="Share via Reddit">Reddit</a>
<a href="{{article.share_post['twitter']}}" title="Share on Twitter">Twitter</a> <a href="{{article.share_post['twitter']}}" title="Share on Twitter">Twitter</a>
<a href="{{article.share_post['bluesky']}}" title="Share on Bluesky">Bluesky</a>
</p> </p>
</section> </section>
{% endif %} {% endif %}

View file

@ -1 +1 @@
from .share_post import * # noqa: F403,PGH004,RUF100 from .share_post import * # noqa

View file

@ -1,4 +1,6 @@
"""Share Post plugin for Pelican. """
Share Post
==========
This plugin was originally created by This plugin was originally created by
Talha Mansoor <talha131@gmail.com> Talha Mansoor <talha131@gmail.com>
@ -96,12 +98,6 @@ def create_link_linkedin(title, url, content):
) )
@create_link
def create_link_bluesky(title, url, content):
# https://docs.bsky.app/docs/advanced-guides/intent-links
return f"https://bsky.app/intent/compose?text={title}%20{url}"
def create_share_links(content): def create_share_links(content):
if isinstance(content, contents.Static): if isinstance(content, contents.Static):
return return
@ -115,10 +111,10 @@ def create_share_links(content):
except AttributeError: except AttributeError:
sub_title = "" sub_title = ""
title = quote(f"{main_title}{sub_title}".encode()) title = quote(f"{main_title}{sub_title}".encode("utf-8"))
site_url = content.settings["SITEURL"] site_url = content.settings["SITEURL"]
url = quote(f"{site_url}/{content.url}".encode()) url = quote(f"{site_url}/{content.url}".encode("utf-8"))
content.share_post = {} content.share_post = {}
for func in _create_link_functions: for func in _create_link_functions:

View file

@ -1,5 +1,7 @@
import os import os
from share_post import run_plugin
from pelican.generators import ArticlesGenerator from pelican.generators import ArticlesGenerator
from pelican.tests.support import get_context, get_settings from pelican.tests.support import get_context, get_settings
@ -24,7 +26,7 @@ def test_share_post(tmp_folder):
) )
generator.generate_context() generator.generate_context()
share_post.run_plugin([generator]) run_plugin([generator])
share_links = generator.articles[0].share_post share_links = generator.articles[0].share_post
@ -61,8 +63,3 @@ def test_share_post(tmp_folder):
share_links["reddit"] share_links["reddit"]
== "https://www.reddit.com/submit?url=/test-post.html&title=Test%20post" == "https://www.reddit.com/submit?url=/test-post.html&title=Test%20post"
) )
assert (
share_links["bluesky"]
== "https://bsky.app/intent/compose?text=Test%20post%20/test-post.html"
)

View file

@ -1,63 +1,51 @@
[project] [tool.poetry]
name = "pelican-share-post" name = "pelican-share-post"
version = "1.2.1" version = "1.1.0"
description = "A Pelican plugin to create share URLs of article" description = "A Pelican plugin to create share URLs of article"
authors = [{name = "Talha Mansoor", email = "talha131@gmail.com"}, {name = "Justin Mayer", email = "entroP@gmail.com"}] authors = ["Talha Mansoor <talha131@gmail.com>", "Justin Mayer <entrop@gmail.com>"]
license = {text = "MIT"} license = "MIT"
readme = "README.md" readme = "README.md"
keywords = ["pelican", "plugin", "social"] keywords = ["pelican", "plugin", "social"]
repository = "https://github.com/pelican-plugins/share-post"
documentation = "https://docs.getpelican.com"
packages = [
{ include = "pelican" },
]
classifiers = [ classifiers = [
"Development Status :: 5 - Production/Stable", "Development Status :: 5 - Production/Stable",
"Environment :: Console", "Environment :: Console",
"Framework :: Pelican", "Framework :: Pelican",
"Framework :: Pelican :: Plugins", "Framework :: Pelican :: Plugins",
"Intended Audience :: End Users/Desktop", "Intended Audience :: End Users/Desktop",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent", "Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP",
"Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Software Development :: Libraries :: Python Modules",
] ]
requires-python = ">=3.8.1,<4.0"
dependencies = [
"pelican>=4.5",
"beautifulsoup4>=4.9.3",
]
[project.urls] [tool.poetry.urls]
Homepage = "https://github.com/pelican-plugins/share-post" "Funding" = "https://donate.getpelican.com/"
"Issue Tracker" = "https://github.com/pelican-plugins/share-post/issues" "Issue Tracker" = "https://github.com/pelican-plugins/share-post/issues"
Funding = "https://donate.getpelican.com/"
[project.optional-dependencies] [tool.poetry.dependencies]
markdown = ["markdown>=3.4"] python = ">=3.7,<4.0"
pelican = ">=4.5"
markdown = {version = ">=3.2.2", optional = true}
beautifulsoup4 = "^4.9.3"
[tool.pdm] [tool.poetry.dev-dependencies]
black = ">=22.3.0"
flake8 = "^3.9"
flake8-black = "^0.3"
invoke = "^2.1"
isort = "^5.4"
markdown = "^3.4"
pytest = "^6.0"
pytest-cov = "^2.8"
pytest-sugar = "^0.9.7"
[tool.pdm.dev-dependencies] [tool.poetry.extras]
lint = [ markdown = ["markdown"]
"invoke>=2.2",
"ruff>=0.5.0,<0.6.0"
]
test = [
"markdown>=3.4",
"pytest>=7.0",
"pytest-cov>=4.0",
"pytest-sugar>=1.0",
]
[tool.pdm.build]
source-includes = [
"CHANGELOG.md",
"CONTRIBUTING.md",
]
includes = ["pelican/"]
excludes = ["**/.DS_Store", "**/test_data/**", "tasks.py"]
[tool.autopub] [tool.autopub]
project-name = "Share Post" project-name = "Share Post"
@ -65,45 +53,18 @@ git-username = "botpub"
git-email = "52496925+botpub@users.noreply.github.com" git-email = "52496925+botpub@users.noreply.github.com"
append-github-contributor = true append-github-contributor = true
[tool.ruff.lint] [tool.isort]
select = [ # Maintain compatibility with Black
"B", # flake8-bugbear profile = "black"
"BLE", # flake8-blind-except multi_line_output = 3
"C4", # flake8-comprehensions
"D", # pydocstyle
"E", # pycodestyle
"F", # pyflakes
"I", # isort
"ICN", # flake8-import-conventions
"ISC", # flake8-implicit-str-concat
"PGH", # pygrep-hooks
"PL", # pylint
"RET", # flake8-return
"RUF", # ruff-specific rules
"SIM", # flake8-simplify
"T10", # flake8-debugger
"T20", # flake8-print
"TID", # flake8-tidy-imports
"TRY", # tryceratops
"UP", # pyupgrade
"W", # pycodestyle
"YTT", # flake8-2020
]
ignore = [ # Sort imports within their section independent of the import type
"D100", # missing docstring in public module force_sort_within_sections = true
"D103", # missing docstring in public method
"D104", # missing docstring in public package
"D203", # blank line before class docstring
"D213", # multi-line docstring summary should start at the second line
"ISC001", # disabled so `ruff format` works without warning
]
[tool.ruff.lint.isort] # Designate "pelican" as separate import section
combine-as-imports = true known_pelican = "pelican"
force-sort-within-sections = true sections = "FUTURE,STDLIB,THIRDPARTY,PELICAN,FIRSTPARTY,LOCALFOLDER"
known-first-party = ["pelican"]
[build-system] [build-system]
requires = ["pdm-backend"] requires = ["poetry-core>=1.0.0"]
build-backend = "pdm.backend" build-backend = "poetry.core.masonry.api"

View file

@ -1,15 +1,14 @@
from inspect import cleandoc from inspect import cleandoc
import logging
import os import os
from pathlib import Path from pathlib import Path
from shutil import which from shutil import which
import sys
from invoke import task from invoke import task
logger = logging.getLogger(__name__)
PKG_NAME = "share_post" PKG_NAME = "share_post"
PKG_PATH = Path(f"pelican/plugins/{PKG_NAME}") PKG_PATH = Path(f"pelican/plugins/{PKG_NAME}")
TOOLS = ("poetry", "pre-commit")
ACTIVE_VENV = os.environ.get("VIRTUAL_ENV", None) ACTIVE_VENV = os.environ.get("VIRTUAL_ENV", None)
VENV_HOME = Path(os.environ.get("WORKON_HOME", "~/.local/share/virtualenvs")) VENV_HOME = Path(os.environ.get("WORKON_HOME", "~/.local/share/virtualenvs"))
@ -17,50 +16,52 @@ VENV_PATH = Path(ACTIVE_VENV) if ACTIVE_VENV else (VENV_HOME.expanduser() / PKG_
VENV = str(VENV_PATH.expanduser()) VENV = str(VENV_PATH.expanduser())
BIN_DIR = "bin" if os.name != "nt" else "Scripts" BIN_DIR = "bin" if os.name != "nt" else "Scripts"
VENV_BIN = Path(VENV) / Path(BIN_DIR) VENV_BIN = Path(VENV) / Path(BIN_DIR)
POETRY = which("poetry") if which("poetry") else (VENV_BIN / "poetry")
TOOLS = ("pdm", "pre-commit") CMD_PREFIX = f"{VENV_BIN}/" if ACTIVE_VENV else f"{POETRY} run "
PDM = which("pdm") if which("pdm") else (VENV_BIN / "pdm")
CMD_PREFIX = f"{VENV_BIN}/" if ACTIVE_VENV else f"{PDM} run "
PRECOMMIT = which("pre-commit") if which("pre-commit") else f"{CMD_PREFIX}pre-commit" PRECOMMIT = which("pre-commit") if which("pre-commit") else f"{CMD_PREFIX}pre-commit"
PTY = os.name != "nt" PTY = True if os.name != "nt" else False
@task @task
def tests(c, deprecations=False): def tests(c):
"""Run the test suite, optionally with `--deprecations`.""" """Run the test suite."""
deprecations_flag = "" if deprecations else "-W ignore::DeprecationWarning" c.run(f"{CMD_PREFIX}pytest", pty=PTY)
c.run(f"{CMD_PREFIX}pytest {deprecations_flag}", pty=PTY)
@task @task
def format(c, check=False, diff=False): def black(c, check=False, diff=False):
"""Run Ruff's auto-formatter, optionally with `--check` or `--diff`.""" """Run Black auto-formatter, optionally with `--check` or `--diff`."""
check_flag, diff_flag = "", "" check_flag, diff_flag = "", ""
if check: if check:
check_flag = "--check" check_flag = "--check"
if diff: if diff:
diff_flag = "--diff" diff_flag = "--diff"
c.run( c.run(f"{CMD_PREFIX}black {check_flag} {diff_flag} {PKG_PATH} tasks.py")
f"{CMD_PREFIX}ruff format {check_flag} {diff_flag} {PKG_PATH} tasks.py", pty=PTY
)
@task @task
def ruff(c, fix=False, diff=False): def isort(c, check=False, diff=False):
"""Run Ruff to ensure code meets project standards.""" """Ensure imports are sorted according to project standards."""
diff_flag, fix_flag = "", "" check_flag, diff_flag = "", ""
if fix: if check:
fix_flag = "--fix" check_flag = "-c"
if diff: if diff:
diff_flag = "--diff" diff_flag = "--diff"
c.run(f"{CMD_PREFIX}ruff check {diff_flag} {fix_flag} .", pty=PTY) c.run(f"{CMD_PREFIX}isort {check_flag} {diff_flag} .")
@task @task
def lint(c, fix=False, diff=False): def flake8(c):
"""Check code for PEP8 compliance via Flake8."""
c.run(f"{CMD_PREFIX}flake8 {PKG_PATH} tasks.py")
@task
def lint(c, diff=False):
"""Check code style via linting tools.""" """Check code style via linting tools."""
ruff(c, fix=fix, diff=diff) isort(c, check=True, diff=diff)
format(c, check=(not fix), diff=diff) black(c, check=True, diff=diff)
flake8(c)
@task @task
@ -68,34 +69,34 @@ def tools(c):
"""Install development tools in the virtual environment if not already on PATH.""" """Install development tools in the virtual environment if not already on PATH."""
for tool in TOOLS: for tool in TOOLS:
if not which(tool): if not which(tool):
logger.info(f"** Installing {tool} **") print(f"** Installing {tool}.")
c.run(f"{CMD_PREFIX}pip install {tool}") c.run(f"{CMD_PREFIX}pip install {tool}")
@task @task
def precommit(c): def precommit(c):
"""Install pre-commit hooks to .git/hooks/pre-commit.""" """Install pre-commit hooks to `.git/hooks/pre-commit`."""
logger.info("** Installing pre-commit hooks **") print("** Installing pre-commit hooks.")
c.run(f"{PRECOMMIT} install") c.run(f"{PRECOMMIT} install")
@task @task
def setup(c): def setup(c):
"""Set up the development environment.""" """Set up the development environment."""
if which("pdm") or ACTIVE_VENV: if which("poetry") or ACTIVE_VENV:
tools(c) tools(c)
c.run(f"{CMD_PREFIX}python -m pip install --upgrade pip", pty=PTY) c.run(f"{CMD_PREFIX}python -m pip install --upgrade pip")
c.run(f"{PDM} update --dev", pty=PTY) c.run(f"{POETRY} install")
precommit(c) precommit(c)
logger.info("\nDevelopment environment should now be set up and ready!\n") print("\nDevelopment environment should now be set up and ready!\n")
else: else:
error_message = """ error_message = """
PDM is not installed, and there is no active virtual environment available. Poetry is not installed, and there is no active virtual environment available.
You can either manually create and activate a virtual environment, or you can You can either manually create and activate a virtual environment, or you can
install PDM via: install Poetry via:
curl -sSL https://raw.githubusercontent.com/pdm-project/pdm/main/install-pdm.py | python3 - curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
Once you have taken one of the above two steps, run `invoke setup` again. Once you have taken one of the above two steps, run `invoke setup` again.
""" # noqa: E501 """ # noqa: E501
raise SystemExit(cleandoc(error_message)) sys.exit(cleandoc(error_message))

3
tox.ini Normal file
View file

@ -0,0 +1,3 @@
[flake8]
max-line-length = 88
ignore = E203, W503