Skip to main content

wagtail-social-share

Auto-share Wagtail Pages on Social Medias.

Supported Social Medias

  • Facebook
  • Twitter

Installation 📦

From PyPi repository:

pip install wagtail-social-share

From source code:

git clone https://github.com/spamz23/wagtail-social-share.git
virtualenv venv
pip install -r requirements.txt

How to use it?

This package is designed to be easily integrable and flexible! 🔥

Here's how you can get started in a few simple steps:

  1. Add wagtail_social_share to your INSTALLED_APPS inside Django settings:
INSTALLED_APPS = (
    # ...
    'wagtail_social_share',
)
  1. Marking a page as sharable:
from wagtail.core.models import Page

from wagtail_social_share.mixins import SocialMediaSharablePageMixin

class BlogPostPage(SocialMediaSharablePageMixin, Page):
    """
    Your custom Wagtail Page model.
    Just inherit the `SocialMediaSharablePageMixin` to
    make it automatically sharable.
    """
  1. Add some configuration settings (inside your Django configs):
# ...

WAGTAIL_SOCIAL_SHARE={
    # The social medias that the pages should be shared on
    "SHARE_ON":["Facebook", "Twitter"],

    # In case you use 'Facebook', you need the following two settings:
    "FACEBOOK_ACCESS_TOKEN": "xxxxxxxxxx", # Replace it with your facebook access token
    "FACEBOOK_APP_ID": "xxxxxxxxxx", # Replace it with your facebook app id

    # In case you use 'Twitter', you need the following four settings:
    "TWITTER_CONSUMER_KEY" : "xxxxxxxxxx", # Replace it with your Twitter Consumer Key
    "TWITTER_CONSUMER_SECRET" : "xxxxxxxxxx", # Replace it with your Twitter Consumer secret
    "TWITTER_TOKEN" : "xxxxxxxxxx", # Replace it with your Twitter Token
    "TWITTER_TOKEN_SECRET" : "xxxxxxxxxx", # Replace it with your Twitter Token Secret

    # Additional Options (Optional):
    "SHARE_IN_DEBUG" : False, # Whether to perform page sharing in DEBUG Mode (defaults to False)
}

That's all the basic configuration needed!

Extra details:

Customizing the shared content

wagtail_social_share provides you the ability to customize the content that will be shared. You just need to override the property share_content inside your Wagtail Page, like so:

from wagtail.core.models import Page

from wagtail_social_share.mixins import SocialMediaSharablePageMixin

class BlogPostPage(SocialMediaSharablePageMixin, Page):
    """
    `SocialMediaSharablePageMixin` uses a property called `share_content`,
    that will by default, return the `search_description` of a Wagtail Page.
    To provide a custom content to share for a page, you can simply override this property.
    """

    @property
    def share_content(self):
        """
        Provide your custom logic for the content.
        In this example we want to share the `title` of a page,
        instead of the `search_description`.
        """
        return self.title

Customizing the share URL

wagtail_social_share provides you the ability to customize the URL that will be shared. This is useful for example if you are using a headless Wagtail, therefore you don't know in advance what the URL will look like in the frontend. How to do this? Easy:

from wagtail.core.models import Page

from wagtail_social_share.mixins import SocialMediaSharablePageMixin

class BlogPostPage(SocialMediaSharablePageMixin, Page):
    """
    `SocialMediaSharablePageMixin` uses a property called `share_url`,
    that will by default, return the property `full_url` of a Wagtail Page.
    To provide a custom URL for a page, you can simply override this property.
    """

    @property
    def share_url(self):
        """
        Provide your custom logic for the URL.
        In this example we assume the URLs for the Blog Posts will be:
        'https://myawesomeblog.com/posts/{blog-post-slug}'
        """
        # Build the URL with the slug
        return "https://myawesomeblog.com/posts/" + self.slug

Exposing the share URL to the Wagtail API

wagtail_social_share provides you the ability to easily expose the share_url property to the Wagtail API. In case you are not familiar with the Wagtail API, please refeer to their documentation.

from wagtail.core.models import Page

from wagtail_social_share.mixins import SocialMediaSharablePageMixin

class BlogPostPage(SocialMediaSharablePageMixin, Page):
    """
    `SocialMediaSharablePageMixin` already provides its own
    `api_fields`. Thefore, you can just simply add them to yours.
    """

    # ... define your page fields

    api_fields = [
        # ... Define your own API Fields
    ] + SocialMediaSharablePageMixin.api_fields

Contributing

All pull requests are welcome! In which ways you can provide your awesome contribution?

Here's some ideas:

  • Adding new social medias;
  • Translating the messages (originally written in Portuguese);
  • Providing new features;
  • Refactor existing code;
  • Writing documentation. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.

Metadata

Release files for wagtail-social-share 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wagtail-social-share 0.1.4
File Size Uploaded Provenance Actions
wagtail-social-share-0.1.4.tar.gz 8.8 kB Without provenance Details for wagtail-social-share-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wagtail-social-share 0.1.4
File Interpreter ABI Platform Actions
wagtail_social_share-0.1.4-py3-none-any.whl Python 3 none any Details for wagtail_social_share-0.1.4-py3-none-any.whl

Total release size: 18.2 kB

Release files / wagtail-social-share-0.1.4.tar.gz

Download URL wagtail-social-share-0.1.4.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9f96676be47a96c3f0c23b42fc9b5bb3f3629b9feb9436d6c103fb856a65624b
BLAKE2b-256 checksum
How to use checksums
916054ab41eef5697c9edb5073a3b4f0ba5b517eeaf003dfe2beb7964500f0da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / wagtail_social_share-0.1.4-py3-none-any.whl

Download URL wagtail_social_share-0.1.4-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c5cb92c475fe025fc8aa36480dc13a87bb43f137d35945cab8ed0d2762a2b90e
BLAKE2b-256 checksum
How to use checksums
9bcaf7a13b2f054aa7f4e2add488770ab1465e901d0002b165ecb9ee06367303
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Security for wagtail-social-share 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page