Skip to content

Commit d69f2b7

Browse files
authored
Merge pull request #20 from jsjoeio/master
feat(readme, package.json, Post.js):add "clean" script and update slugify function
2 parents 3fc039b + 923e5c2 commit d69f2b7

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ If you'd like to learn more about persisted queries, email [[email protected]
1212

1313
## Setup
1414

15-
Use an existing OneGraph app or sign up sign up at [OneGraph](https://www.onegraph.com) to create a new app. Update the `/.env` file to update the `RAZZLE_ONEGRAPH_APP_ID` with your app's id. This would also be a good time to replace `REPOSITORY_FIXED_VARIABLES` in the `/.env` file with the repo name and owner for the repo you'd like to back your blog (it uses this repo's issues by default).
15+
Use an existing OneGraph app or sign up sign up at [OneGraph](https://www.onegraph.com) to create a new app. Update the `/.env` file to update the `RAZZLE_ONEGRAPH_APP_ID` with your app's id. This would also be a good time to replace `REPOSITORY_FIXED_VARIABLES` in the `/.env` file with the repo name and owner for the repo you'd like to back your blog (it uses this repo's issues by default).
1616

1717
Remove the generated files (they're tied to the OneGraph app they were generated with)
1818

1919
```
20-
rm -r src/__generated__
20+
yarn relay:clean
21+
# which runs rm -r src/__generated__
2122
```
2223

2324
(Note: any time you change the variables in `.env`, it's a good idea to stop the relay compiler, remove the files in `src/__generated__`, and restart the compiler)
@@ -46,7 +47,6 @@ OG_GITHUB_TOKEN='<your-github-token>' \
4647

4748
You may need to install [watchman](https://facebook.github.io/watchman/), a file watching service. On mac, do `brew install watchman`. On Windows or Linux, follow the instructions at [https://facebook.github.io/watchman/docs/install.html](https://facebook.github.io/watchman/docs/install.html).
4849

49-
5050
### Start the server
5151

5252
Now that we've generated the relay files, we can start the server.
@@ -57,7 +57,6 @@ yarn start
5757

5858
The project will load at [http://localhost:3000](http://localhost:3000).
5959

60-
6160
## Deploying
6261

6362
The project comes with setups for deploying to Google's Firebase, Zeit's Now, Netlify, and Fly.io.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"test": "razzle test --env=jsdom",
4040
"start:prod": "NODE_ENV=production node build/server.js",
4141
"relay": "relay-compiler --src ./src --schema ./schema.graphql --persistFunction scripts/persistQuery.js",
42+
"relay:clean": "rm -r src/__generated__",
4243
"flow": "flow",
4344
"fetch-schema": "node scripts/fetchSchema.js --path schema.graphql",
4445
"analyze": "source-map-explorer 'build/public/static/js/*.js'",

src/Post.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,13 @@ export const ReactionBar = ({
347347
};
348348

349349
function slugify(s: string): string {
350-
return lowerCase(s).replace(/[^A-Za-z0-9-]+/g, '-');
350+
return lowerCase(s)
351+
.replace(/\s+/g, '-') // Replace spaces with -
352+
.replace(/&/g, '-and-') // Replace & with 'and'
353+
.replace(/[^\w\-]+/g, '') // Remove all non-word characters
354+
.replace(/\-\-+/g, '-') // Replace multiple - with single -
355+
.trimStart() // Trim from start of text
356+
.trimEnd(); // Trim from end of text
351357
}
352358

353359
export function postUrl({

0 commit comments

Comments
 (0)