Skip to content

Commit

Permalink
fixed the markup issue for Explore Waterloo Region events
Browse files Browse the repository at this point in the history
  • Loading branch information
s-kennedy committed Sep 1, 2024
1 parent 94d887b commit 3825a22
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"eslint": "8.28.0",
"eslint-config-next": "13.0.4",
"gray-matter": "^4.0.3",
"html-entities": "^2.5.2",
"ics": "^3.7.6",
"luxon": "^3.4.4",
"marked": "^13.0.2",
Expand Down
23 changes: 23 additions & 0 deletions pages/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { NodeHtmlMarkdown } from 'node-html-markdown'
const markdown = new NodeHtmlMarkdown()
import dynamic from 'next/dynamic'
import {decode} from 'html-entities';
const ReactMarkdown = dynamic(() => import('react-markdown'))

export default function Test() {

const original = `<p>Experience the ultimate combination of gourmet delights and scenic beauty with Waterloo Central Railway\\'s “Brew & Bite” trains!</p>\\n`
const decoded = decode(original)
const cleaned = decoded.replace(/&#(\d+);/g, (m, d) => String.fromCharCode(d))
const uriDecoded = decodeURIComponent(cleaned)
const trimmed = uriDecoded.replace(/\\n|\\/g, "")
const description = markdown.translate(trimmed)

return (
<>
<ReactMarkdown>{description}</ReactMarkdown>
</>
)
}


10 changes: 8 additions & 2 deletions utils/import-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { NodeHtmlMarkdown } from 'node-html-markdown'
import { DateTime } from 'luxon'
import cheerio from "cheerio"
import {decode} from 'html-entities';

const directus = createDirectus('https://cms.connectedkw.com').with(rest()).with(staticToken(process.env.DIRECTUS_TOKEN));
const markdown = new NodeHtmlMarkdown()
Expand Down Expand Up @@ -48,7 +49,7 @@ export const importExploreWaterlooEvents = async (endpoint=EVENTS_ENDPOINT, even
try {
const response = await fetch(endpoint, {
method: "POST",
body: `url=${encodeURIComponent('https://explorewaterloo.ca/events/month/')}`,
body: `url=${encodeURIComponent('https://explorewaterloo.ca/events/month/')}&view_data%5Btribe-bar-date%5D=2024-09`,
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
},
Expand Down Expand Up @@ -94,7 +95,12 @@ const saveToDatabase = async(events) => {
const promises = events.map(async(event) => {
try {
const title = event.name?.replace(/&#(\d+);/g, (m, d) => String.fromCharCode(d))
const description = event.description?.replace(/&#(\d+);/g, (m, d) => String.fromCharCode(d))
const originalDescription = event.description
const decoded = decode(originalDescription)
const cleaned = decoded.replace(/&#(\d+);/g, (m, d) => String.fromCharCode(d))
const uriDecoded = decodeURIComponent(cleaned)
const trimmed = uriDecoded.replace(/\\n|\\/g, "")
const description = markdown.translate(trimmed)
const location_source_text = event.location?.name ? [event.location.name,event.location.address?.streetAddress].join(", ").replace(/&#(\d+);/g, (m, d) => String.fromCharCode(d)) : null
const image = await importImage(event.image, title)

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3776,6 +3776,11 @@ hoist-non-react-statics@^3.0.0, hoist-non-react-statics@^3.3.0:
dependencies:
react-is "^16.7.0"

html-entities@^2.5.2:
version "2.5.2"
resolved "https://registry.yarnpkg.com/html-entities/-/html-entities-2.5.2.tgz#201a3cf95d3a15be7099521620d19dfb4f65359f"
integrity sha512-K//PSRMQk4FZ78Kyau+mZurHn3FH0Vwr+H36eE0rPbeYkRRi9YxceYPhuN60UwWorxyKHhqoAJl2OFKa4BVtaA==

html-void-elements@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/html-void-elements/-/html-void-elements-3.0.0.tgz#fc9dbd84af9e747249034d4d62602def6517f1d7"
Expand Down

0 comments on commit 3825a22

Please sign in to comment.