Auto-share Wagtail Pages on Social Medias
Project description
wagtail-social-share
Auto-share Wagtail Pages on Social Medias.
Installation :package:
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! :fire:
Here's how you can get started in a few simple steps:
- Add
wagtail_social_share
to yourINSTALLED_APPS
inside Django settings:
INSTALLED_APPS = (
# ...
'wagtail_social_share',
)
- 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.
"""
- 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 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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for WAGTAIL-SOCIAL-SHARE-0.0.6.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbc9eae368b954dd723f4a32b9f20a1e66456f8bbb0ed41737c784124106238b |
|
MD5 | 0032e8ca97361a2dfe2bd189e996594f |
|
BLAKE2b-256 | e715e7afef50076299ca80bc346b1ac79d5b3fa76644a4b28b03f18a3e810d92 |
Hashes for WAGTAIL_SOCIAL_SHARE-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e28ed5995c92969248661a2ee0460a2915fa0352b50e01a3a67f57347d51952 |
|
MD5 | bcf8707c921f1ebee3a1b82cf82a951d |
|
BLAKE2b-256 | 6a3262bd9c25ef276c4bbf88dd1056416b0c1e030f201108acbc017d57d53094 |