Automatically replace Ghost content URLs with direct links

Media requestn now go directly to media.snipettemag.com instead
of getting routed to /content/images on the Ghost site. NOTE: This
only applies to the content of posts and pages, not to other media
such as site headings, profile pictures, etc.
This commit is contained in:
Hippo 2019-10-06 18:06:12 +05:30
parent 173c5c5654
commit 63421d67e4
3 changed files with 8 additions and 2 deletions

View file

@ -5,6 +5,8 @@ import Helmet from 'react-helmet'
import { Layout } from '../components/common' import { Layout } from '../components/common'
import { MetaData } from '../components/common/meta' import { MetaData } from '../components/common/meta'
import config from '../utils/siteConfig'
/** /**
* Single page (/:slug) * Single page (/:slug)
@ -33,7 +35,7 @@ const Page = ({ data, location }) => {
{/* The main page content */} {/* The main page content */}
<section <section
className="content-body load-external-scripts" className="content-body load-external-scripts"
dangerouslySetInnerHTML={{ __html: page.html }} dangerouslySetInnerHTML={{ __html: page.html.replace(new RegExp(config.mediaUrlFrom, 'g'), config.mediaUrlTo) }}
/> />
</article> </article>
</div> </div>

View file

@ -6,6 +6,7 @@ import Helmet from 'react-helmet'
import { Layout } from '../components/common' import { Layout } from '../components/common'
import { MetaData } from '../components/common/meta' import { MetaData } from '../components/common/meta'
import config from '../utils/siteConfig'
/** /**
* Single post view (/:slug) * Single post view (/:slug)
@ -39,7 +40,7 @@ const Post = ({ data, location }) => {
{/* The main post content */ } {/* The main post content */ }
<section <section
className="content-body load-external-scripts" className="content-body load-external-scripts"
dangerouslySetInnerHTML={{ __html: post.html }} dangerouslySetInnerHTML={{ __html: post.html.replace(new RegExp(config.mediaUrlFrom, 'g'), config.mediaUrlTo) }}
/> />
<section className="content-footer"> <section className="content-footer">
<p> <p>

View file

@ -1,6 +1,9 @@
module.exports = { module.exports = {
siteUrl: `https://www.snipettemag.com`, // Site domain. Do not include a trailing slash! siteUrl: `https://www.snipettemag.com`, // Site domain. Do not include a trailing slash!
mediaUrlFrom: `https://snipette-ghost.herokuapp.com/content/images/`, // skip Ghost content URL...
mediaUrlTo: `https://media.snipettemag.com/`, // ...and get it directly from source!
postsPerPage: 12, // Number of posts shown on paginated pages (changes this requires sometimes to delete the cache) postsPerPage: 12, // Number of posts shown on paginated pages (changes this requires sometimes to delete the cache)
siteTitleMeta: `Snipette`, // This allows an alternative site title for meta data for pages. siteTitleMeta: `Snipette`, // This allows an alternative site title for meta data for pages.