From 61f46d4058c3abaca8a71f88704ac3fb6b3be711 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Sun, 24 Nov 2019 14:29:25 +0100 Subject: [PATCH] refactor jest config, add more tests --- README.md | 2 +- jest.config.js | 7 +- jest/__fixtures__/avatar.json | 32 +-- jest/__fixtures__/github.json | 219 ++++++++++++++++++ jest/__fixtures__/meta.json | 39 ++++ jest/__fixtures__/photos.json | 62 +++++ jest/__fixtures__/post.json | 41 ++++ jest/__fixtures__/posts.json | 118 ++++++++++ jest/__mocks__/file-mock.js | 1 + jest/__mocks__/file-mock.ts | 1 - jest/__mocks__/gatsby.js | 29 +++ jest/__mocks__/gatsby.ts | 14 -- jest/__mocks__/svgr-mock.js | 6 + jest/__mocks__/svgr-mock.ts | 3 - jest/setup-test-env.ts | 17 ++ package.json | 2 +- src/@types/Image.d.ts | 2 +- src/components/Layout.test.tsx | 7 + src/components/atoms/Changelog.test.tsx | 30 +-- src/components/atoms/Changelog.tsx | 40 ++-- src/components/atoms/Container.test.tsx | 9 - src/components/atoms/Copy.tsx | 2 +- src/components/atoms/Hamburger.test.tsx | 9 - src/components/atoms/Time.test.tsx | 16 -- src/components/molecules/Featured.tsx | 53 ++--- .../molecules}/PostTeaser.module.scss | 0 .../molecules}/PostTeaser.tsx | 27 ++- src/components/molecules/RelatedPosts.tsx | 20 +- .../molecules/Search/SearchResults.tsx | 15 +- src/components/molecules/ThemeSwitch.tsx | 19 +- src/components/molecules/Vcard.test.tsx | 28 --- src/components/molecules/Vcard.tsx | 62 ++--- src/components/organisms/Footer.test.tsx | 7 + src/components/organisms/Header.test.tsx | 7 + src/hooks/use-site-metadata.ts | 58 ++--- src/pages/__tests__/404.test.tsx | 13 ++ src/pages/__tests__/photos.test.tsx | 17 ++ src/pages/__tests__/tags.test.tsx | 24 ++ src/pages/__tests__/thanks.test.tsx | 13 ++ src/pages/photos.tsx | 4 +- src/templates/Post/index.test.tsx | 17 ++ src/templates/Posts.test.tsx | 28 +++ src/templates/Posts.tsx | 2 +- 43 files changed, 834 insertions(+), 288 deletions(-) create mode 100644 jest/__fixtures__/github.json create mode 100644 jest/__fixtures__/meta.json create mode 100644 jest/__fixtures__/photos.json create mode 100644 jest/__fixtures__/post.json create mode 100644 jest/__fixtures__/posts.json create mode 100644 jest/__mocks__/file-mock.js delete mode 100644 jest/__mocks__/file-mock.ts create mode 100644 jest/__mocks__/gatsby.js delete mode 100644 jest/__mocks__/gatsby.ts create mode 100644 jest/__mocks__/svgr-mock.js delete mode 100644 jest/__mocks__/svgr-mock.ts create mode 100644 src/components/Layout.test.tsx delete mode 100644 src/components/atoms/Container.test.tsx delete mode 100644 src/components/atoms/Hamburger.test.tsx delete mode 100644 src/components/atoms/Time.test.tsx rename src/{templates/Post => components/molecules}/PostTeaser.module.scss (100%) rename src/{templates/Post => components/molecules}/PostTeaser.tsx (58%) delete mode 100644 src/components/molecules/Vcard.test.tsx create mode 100644 src/components/organisms/Footer.test.tsx create mode 100644 src/components/organisms/Header.test.tsx create mode 100644 src/pages/__tests__/404.test.tsx create mode 100644 src/pages/__tests__/photos.test.tsx create mode 100644 src/pages/__tests__/tags.test.tsx create mode 100644 src/pages/__tests__/thanks.test.tsx create mode 100644 src/templates/Post/index.test.tsx create mode 100644 src/templates/Posts.test.tsx diff --git a/README.md b/README.md index 8ddb7b98..f0581ad0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@

- 🍭 My blog built with Gatsby. Neat. + 🍭 My blog built with Gatsby + TypeScript. Neat.

kremalicious.com diff --git a/jest.config.js b/jest.config.js index d84fce0a..884f8d28 100644 --- a/jest.config.js +++ b/jest.config.js @@ -3,12 +3,12 @@ module.exports = { '^.+\\.(tsx?|jsx?)$': 'ts-jest', '^.+\\.jsx?$': '/jest/jest-preprocess.js' }, - testRegex: '(/__tests__/.*|\\.(test|spec))\\.(ts|tsx)$', + testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.([tj]sx?)$', moduleNameMapper: { '.+\\.(css|styl|less|sass|scss)$': 'identity-obj-proxy', '.+\\.(jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': - '/jest/__mocks__/file-mock.ts', - '\\.svg': '/jest/__mocks__/svgr-mock.ts' + '/jest/__mocks__/file-mock.js', + '\\.svg': '/jest/__mocks__/svgr-mock.js' }, moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], testPathIgnorePatterns: ['node_modules', '.cache', 'public', 'coverage'], @@ -16,7 +16,6 @@ module.exports = { globals: { __PATH_PREFIX__: '' }, - testURL: 'http://localhost', setupFiles: ['/jest/loadershim.js'], setupFilesAfterEnv: ['/jest/setup-test-env.ts'], collectCoverageFrom: ['src/**/*.{ts,tsx}', '!src/@types/**/*'] diff --git a/jest/__fixtures__/avatar.json b/jest/__fixtures__/avatar.json index f540fd70..dfd08cc5 100644 --- a/jest/__fixtures__/avatar.json +++ b/jest/__fixtures__/avatar.json @@ -1,20 +1,22 @@ { - "edges": [ - { - "node": { - "childImageSharp": { - "fixed": { - "aspectRatio": 1, - "width": 80, - "height": 80, - "src": "/static/b61a09d5f4cbd9d8b2844091590ddea4/fce1d/avatar.jpg", - "srcSet": "/static/b61a09d5f4cbd9d8b2844091590ddea4/fce1d/avatar.jpg 1x,\n/static/b61a09d5f4cbd9d8b2844091590ddea4/c4de8/avatar.jpg 1.5x,\n/static/b61a09d5f4cbd9d8b2844091590ddea4/c3234/avatar.jpg 2x", - "srcWebp": "/static/b61a09d5f4cbd9d8b2844091590ddea4/ad6b8/avatar.webp", - "srcSetWebp": "/static/b61a09d5f4cbd9d8b2844091590ddea4/ad6b8/avatar.webp 1x,\n/static/b61a09d5f4cbd9d8b2844091590ddea4/5c322/avatar.webp 1.5x,\n/static/b61a09d5f4cbd9d8b2844091590ddea4/5bf6b/avatar.webp 2x", - "originalName": "avatar.jpg" + "avatar": { + "edges": [ + { + "node": { + "childImageSharp": { + "fixed": { + "aspectRatio": 1, + "width": 80, + "height": 80, + "src": "/static/b61a09d5f4cbd9d8b2844091590ddea4/fce1d/avatar.jpg", + "srcSet": "/static/b61a09d5f4cbd9d8b2844091590ddea4/fce1d/avatar.jpg 1x,\n/static/b61a09d5f4cbd9d8b2844091590ddea4/c4de8/avatar.jpg 1.5x,\n/static/b61a09d5f4cbd9d8b2844091590ddea4/c3234/avatar.jpg 2x", + "srcWebp": "/static/b61a09d5f4cbd9d8b2844091590ddea4/ad6b8/avatar.webp", + "srcSetWebp": "/static/b61a09d5f4cbd9d8b2844091590ddea4/ad6b8/avatar.webp 1x,\n/static/b61a09d5f4cbd9d8b2844091590ddea4/5c322/avatar.webp 1.5x,\n/static/b61a09d5f4cbd9d8b2844091590ddea4/5bf6b/avatar.webp 2x", + "originalName": "avatar.jpg" + } } } } - } - ] + ] + } } diff --git a/jest/__fixtures__/github.json b/jest/__fixtures__/github.json new file mode 100644 index 00000000..b29585d4 --- /dev/null +++ b/jest/__fixtures__/github.json @@ -0,0 +1,219 @@ +{ + "github": { + "viewer": { + "repositories": { + "edges": [ + { + "node": { + "name": "csspaperstack", + "url": "https://github.com/kremalicious/csspaperstack", + "owner": { + "login": "kremalicious" + }, + "object": null + } + }, + { + "node": { + "name": "hastuzeit", + "url": "https://github.com/kremalicious/hastuzeit", + "owner": { + "login": "kremalicious" + }, + "object": null + } + }, + { + "node": { + "name": "Badged", + "url": "https://github.com/kremalicious/Badged", + "owner": { + "login": "kremalicious" + }, + "object": null + } + }, + { + "node": { + "name": "hsresponsive", + "url": "https://github.com/kremalicious/hsresponsive", + "owner": { + "login": "kremalicious" + }, + "object": null + } + }, + { + "node": { + "name": "dribbble-chromeapp", + "url": "https://github.com/kremalicious/dribbble-chromeapp", + "owner": { + "login": "kremalicious" + }, + "object": null + } + }, + { + "node": { + "name": "krtmn", + "url": "https://github.com/kremalicious/krtmn", + "owner": { + "login": "kremalicious" + }, + "object": { + "id": "MDQ6QmxvYjM2MzA0MzQ6NDcwYWRiOTc5MWVjYzZkNmU0YzMzNDQ3ZmZhZjBhNjA0ZGE1NTBkNA==", + "text": "YOURLS Changelog\n================\n\n_This file lists the main changes through all versions of YOURLS. \nFor a much more detailed list, simply refer to [commit messages](https://github.com/YOURLS/YOURLS/commits/master)._\n\n1.7\n---\n- added: support for PDO and MySQLi\n- added: social bookmarklets - share on Twitter, Facebook or Tumblr in a click\n- added: check api.yourls.org if a new version of YOURLS is available\n- added: proxy support - install YOURLS behind a firewall!\n- improved: security regarding SQL injections\n- improved: security regarding your credentials - now auto-encrypted\n- improved: external HTTP request handling\n- improved: ƒυηкƴ UTF-8 titles handling\n- fixed: compatibility with Apache mod_security blocking bookmarklets\n- fixed: lots of bugs\n\n1.6\n---\n- added: مرحبا العالم! Hej verden! 你好世界! Kumusta mundo! Ciao mondo! Hello world! Translation API.\n- added: custom API actions\n- added: support for URLs with common protocols\n- fixed: search and pagination in the admin interface\n- updated: third party libs jQuery, ezSQL, GeoIP\n- improved: sanitizing and escaping functions\n\n1.5.1\n-----\n- added: full jsonp support\n- added: ability to use encrypted passwords in the config file\n- fixed: support for http://www.sho.rt/bleh and http://sho.rt/bleh\n- added: support for any favicon dropped in the /user directory\n- updated: Google Visualization API instead of deprecated Google Charts\n- fixed: bugs, bugs, bugs\n- added: hooks, hooks, hooks\n- improved: things, things, things\n\n1.5\n---\n- added: plugin architecture! OMG plugins!!1!!1!\n- added: directory /user, config.php can be moved there\n- added: new \"instant bookmarklets\"\n- added: 1 click copy-to-clipboard a la bitly\n- change in logic: now all request are handled by PHP and don't rely on .htaccess\n- added: saving URL titles\n- added: support for prefix-n-shorten: sho.rt/http://example.com/\n- added: core plugin to allow hyphens in URLs\n- added: core sample plugin to wrap redirected URLs in a social toolbar\n- added: core sample plugin to show how to create administration page in plugins\n- added: core plugin to display a random pretty background\n- changed: layout now using a more consistent palette, see http://yourls.org/palette\n- added: anti XSS and anti CSRF measures\n- added: interactive map if possible in stat traffic by countries\n- fixed: lots of bugs\n\n1.4.3\n-----\n- fixed bug no-stats-showing-ffs due to inconsistency in DB schema\n- improve error reporting with API method url-stat\n\n1.4.2\n-----\n- fixed: bug in auth function\n- added: sample public API file\n- added: check in API requests for WordPress plugin when adding a new short URL\n- prettier sample public interface\n\n1.4.1\n-----\n- fixed: base 62 URLs (keywords with MiXeD CaSe)\n- new & secure auth method for API calls, with no need to use login & password combo\n- allow SSL enforcement for admin pages\n- new API method: stats for individual URL.\n- prevent internal redirection loops\n- filter and search URLs & short URLs by date\n\n1.4\n---\n- added: an upgrader from 1.3 to 1.4\n- change in logic: now using a global object $ydb for everything related to DB and other globally needed stuff\n- change in logic: include \"load-yourls.php\" instead of \"config.php\" to start engine\n- change in DB schema: now storing URLs with their keyword as used in shorturl, allowing for any keyword length\n- change in DB schema: new table for storing various options including next_id, dropping table of the same name\n- change in DB schema: new table for storing hits (for stats)\n- improved the installer, with .htaccess file creation\n- layout tweak: now prettier, isn't it?\n- stats! OMG stats!\n\n1.3-RC1\n-------\n- added bookmarklet and tools page\n- improved XSS filter when adding new URL\n- code cleanup in admin/index.php to separate code and display\n- added favicon\n- stricter coding to prevent notices with undefined indexes\n- hide PHP notices & SQL errors & warnings, unless YOURLS_DEBUG constant set to true\n\n1.2\n---\n- don't remember. A few tiny stuff for sure.\n\n1.1\n---\n- don't remember. Some little bugs I guess.\n\n1.0.1\n-----\n- don't remember. Trivial stuff probably.\n\n1.0\n---\n- initial release\n" + } + } + }, + { + "node": { + "name": "glassfruit", + "url": "https://github.com/kremalicious/glassfruit", + "owner": { + "login": "kremalicious" + }, + "object": null + } + }, + { + "node": { + "name": "kremalicious2", + "url": "https://github.com/kremalicious/kremalicious2", + "owner": { + "login": "kremalicious" + }, + "object": null + } + }, + { + "node": { + "name": "wp-icons-template", + "url": "https://github.com/kremalicious/wp-icons-template", + "owner": { + "login": "kremalicious" + }, + "object": null + } + }, + { + "node": { + "name": "kbdfun", + "url": "https://github.com/kremalicious/kbdfun", + "owner": { + "login": "kremalicious" + }, + "object": null + } + }, + { + "node": { + "name": "dotfiles", + "url": "https://github.com/kremalicious/dotfiles", + "owner": { + "login": "kremalicious" + }, + "object": null + } + }, + { + "node": { + "name": "kretschmann.io", + "url": "https://github.com/kremalicious/kretschmann.io", + "owner": { + "login": "kremalicious" + }, + "object": null + } + }, + { + "node": { + "name": "blog", + "url": "https://github.com/kremalicious/blog", + "owner": { + "login": "kremalicious" + }, + "object": null + } + }, + { + "node": { + "name": "files", + "url": "https://github.com/kremalicious/files", + "owner": { + "login": "kremalicious" + }, + "object": null + } + }, + { + "node": { + "name": "appstorebadges", + "url": "https://github.com/kremalicious/appstorebadges", + "owner": { + "login": "kremalicious" + }, + "object": null + } + }, + { + "node": { + "name": "hyper-mac-pro", + "url": "https://github.com/kremalicious/hyper-mac-pro", + "owner": { + "login": "kremalicious" + }, + "object": null + } + }, + { + "node": { + "name": "ipfs-hosting", + "url": "https://github.com/kremalicious/ipfs-hosting", + "owner": { + "login": "kremalicious" + }, + "object": null + } + }, + { + "node": { + "name": "gatsby-plugin-matomo", + "url": "https://github.com/kremalicious/gatsby-plugin-matomo", + "owner": { + "login": "kremalicious" + }, + "object": { + "id": "MDQ6QmxvYjEzMjQ5NDg4NTozNzMwOWUxMTc4MTA5YjJmZDQ3ZDg5YTZlZjIwNjM5NTNlNDNlZjA1", + "text": "### Changelog\n\nAll notable changes to this project will be documented in this file. Dates are displayed in UTC.\n\nGenerated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).\n\n#### [v0.7.2](https://github.com/kremalicious/gatsby-plugin-matomo/compare/v0.7.1...v0.7.2)\n\n> 13 June 2019\n\n- Fix missing tracking code in rendered HTML [`#18`](https://github.com/kremalicious/gatsby-plugin-matomo/pull/18)\n- update changelog [`57092e5`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/57092e5b0f755867885d4877ba539e2e684eba3c)\n- Release 0.7.2 [`31cabd6`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/31cabd60afbf9da39bce3cbd9187ba203c8f6e93)\n\n#### [v0.7.1](https://github.com/kremalicious/gatsby-plugin-matomo/compare/0.7.0...v0.7.1)\n\n> 10 June 2019\n\n- preconnect to configured Matomo host url [`#17`](https://github.com/kremalicious/gatsby-plugin-matomo/pull/17)\n- Add prettier [`#16`](https://github.com/kremalicious/gatsby-plugin-matomo/pull/16)\n- add prettier [`858fc2e`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/858fc2eb8a58dc49cfe1fea77d2b71c7d2ac4888)\n- new release-it setup [`bbb5f19`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/bbb5f19f94b867b7f7f6959a201690c290ac0fe2)\n- bump packages [`e3479f6`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/e3479f6955f6324140e7243b0f680dd3771250f7)\n\n#### [0.7.0](https://github.com/kremalicious/gatsby-plugin-matomo/compare/0.6.1...0.7.0)\n\n> 30 March 2019\n\n- Page tracking improvements [`#15`](https://github.com/kremalicious/gatsby-plugin-matomo/pull/15)\n- capture and send custom page title [`#11`](https://github.com/kremalicious/gatsby-plugin-matomo/issues/11)\n- better page url & referrer url tracking [`04b8ba1`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/04b8ba19038f49571a0f19099f9af4575739a8fb)\n- update changelog [`24f57da`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/24f57da352ee95781ed2c4268f31adaaa5aa1d82)\n- Release 0.7.0 [`4c36d9c`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/4c36d9c7c6212542fc1b3ebba977ee9c1e9bc526)\n\n#### [0.6.1](https://github.com/kremalicious/gatsby-plugin-matomo/compare/v0.6.0...0.6.1)\n\n> 30 March 2019\n\n- package updates [`#14`](https://github.com/kremalicious/gatsby-plugin-matomo/pull/14)\n- Update release-it to the latest version 🚀 [`#12`](https://github.com/kremalicious/gatsby-plugin-matomo/pull/12)\n- Update release-it to the latest version 🚀 [`#10`](https://github.com/kremalicious/gatsby-plugin-matomo/pull/10)\n- run changelog before release [`5da11a4`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/5da11a47609f48328d544bab07600576c6f060e0)\n- Release 0.6.1 [`f62c5bf`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/f62c5bf2926726bfc649d24b7fd555974c10482f)\n- chore(package): update release-it to version 10.0.0 [`d56c6c3`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/d56c6c3dba6607f5d67bf70a0953a8d922d84298)\n\n#### [v0.6.0](https://github.com/kremalicious/gatsby-plugin-matomo/compare/v0.5.1...v0.6.0)\n\n> 5 December 2018\n\n- Path exclusion [`#9`](https://github.com/kremalicious/gatsby-plugin-matomo/pull/9)\n- add changelog [`2b268a1`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/2b268a1c6c0df2b4e344c1f965a665e7be8d9341)\n- allow exclusion of paths [`9464d47`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/9464d47ae1b191ef494148fab4af200e3ea9c85c)\n- make release-it work with conventional-changelog [`2dcd5a7`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/2dcd5a7d02a2c35b95ddbec44d2319b0b25dc682)\n\n#### [v0.5.1](https://github.com/kremalicious/gatsby-plugin-matomo/compare/v0.5.0...v0.5.1)\n\n> 21 November 2018\n\n- Update release-it to the latest version 🚀 [`#8`](https://github.com/kremalicious/gatsby-plugin-matomo/pull/8)\n- bump packages [`cb26a40`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/cb26a40ece69e756862c5b6986eed60acca61bdd)\n- new Matomo logo [`64dd425`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/64dd4259ecda1fba49ac2bbfba7727bd5a544e3c)\n- Release 0.5.1 [`c442282`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/c44228275734a5edcf790a0bd8c91b9eec634891)\n\n#### [v0.5.0](https://github.com/kremalicious/gatsby-plugin-matomo/compare/v0.4.1...v0.5.0)\n\n> 6 August 2018\n\n- Add consent mode [`#7`](https://github.com/kremalicious/gatsby-plugin-matomo/pull/7)\n- Scoping js variables to avoid polluting global scope [`#6`](https://github.com/kremalicious/gatsby-plugin-matomo/pull/6)\n- bump packages [`b08b4a5`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/b08b4a5a45c477898b53831e48109bd672e3e11d)\n- add codeclimate config [`a96e8ea`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/a96e8ea5f89fdc07f84bdd49b927c5c757cf4665)\n- Add disableCookies option [`ff9a2c7`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/ff9a2c755867e60964953c109ab382915b662279)\n\n#### [v0.4.1](https://github.com/kremalicious/gatsby-plugin-matomo/compare/v0.4.0...v0.4.1)\n\n> 28 June 2018\n\n- Update eslint to the latest version 🚀 [`#5`](https://github.com/kremalicious/gatsby-plugin-matomo/pull/5)\n- improvements for SPA tracking [`7d653d5`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/7d653d564cb0ca4ae05d6897d94185ea2198462e)\n- package updates [`347f951`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/347f951174ec6b9f31b91cbd7bce90178eb49a1a)\n- Release 0.4.1 [`b254c13`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/b254c130b9ee8c750e2dd3f69540537094eac235)\n\n#### [v0.4.0](https://github.com/kremalicious/gatsby-plugin-matomo/compare/v0.3.2...v0.4.0)\n\n> 19 June 2018\n\n- Updates for Gatsby v2 [`#4`](https://github.com/kremalicious/gatsby-plugin-matomo/pull/4)\n- updates for Gatsby v2 [`59e442a`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/59e442a31d85af27f8cdf65a2d15ed8601995fad)\n- package updates [`356e68f`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/356e68faf500baf4c69461fa8323995f30400e24)\n- Release 0.4.0 [`1173236`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/117323688af1963ca5602b13ddd6131aba70376c)\n\n#### [v0.3.2](https://github.com/kremalicious/gatsby-plugin-matomo/compare/v0.3.1...v0.3.2)\n\n> 23 May 2018\n\n- save some lines [`5034a3b`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/5034a3b8e5201d976f7deb210b471caa50ea16cd)\n- Release 0.3.2 [`c531e47`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/c531e47cf5905acda149a637606ecfea9e2e40bc)\n- change repository field [`260273e`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/260273e0139db6d5bf76bc29c37d2f93fd254f05)\n\n#### [v0.3.1](https://github.com/kremalicious/gatsby-plugin-matomo/compare/v0.3.0...v0.3.1)\n\n> 14 May 2018\n\n- package updates [`2acbd45`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/2acbd450cb7dffe39c3cb57edbad5aeebe6d7799)\n- Release 0.3.1 [`f9050ce`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/f9050ceaa2b8d214d113ca78785bb7ba78f14d5a)\n- fix environment check [`dc574ab`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/dc574ab72c4ec01c4fa995ae9aa9a1469f04387a)\n\n#### [v0.3.0](https://github.com/kremalicious/gatsby-plugin-matomo/compare/v0.2.0...v0.3.0)\n\n> 10 May 2018\n\n- allow local piwik.js path to be set [`a15146c`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/a15146c3dc6b692070e09b38646ad925fc92fb28)\n- Release 0.3.0 [`2e36f13`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/2e36f1383d39703d10405b9e82782a6efa54d56f)\n\n#### [v0.2.0](https://github.com/kremalicious/gatsby-plugin-matomo/compare/v0.1.3...v0.2.0)\n\n> 8 May 2018\n\n- add dev mode [`5c05efe`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/5c05efe1815fb617e0153924696dc6350e2e753c)\n- Release 0.2.0 [`a3ef6d4`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/a3ef6d4c635a15d6cc64c7c3735f551737f3eff7)\n\n#### [v0.1.3](https://github.com/kremalicious/gatsby-plugin-matomo/compare/v0.1.2...v0.1.3)\n\n> 8 May 2018\n\n- readme updates [`49640f4`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/49640f4d37b54728c5a80ae9f2c63cb103318386)\n- Release 0.1.3 [`0109e19`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/0109e19e106f8620056db2775205101bf4cc1c3b)\n\n#### [v0.1.2](https://github.com/kremalicious/gatsby-plugin-matomo/compare/v0.1.1...v0.1.2)\n\n> 8 May 2018\n\n- Add Greenkeeper badge 🌴 [`#1`](https://github.com/kremalicious/gatsby-plugin-matomo/pull/1)\n- do nothing on route updates when piwik isn't loaded and in development [`6c0a840`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/6c0a840de21ce46f544b6ce9a7dd63e961e7ab6b)\n- move greenskeeper badge [`b361eef`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/b361eef43bc85c7acf8be73f3067686912ac49b3)\n- Release 0.1.2 [`370025f`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/370025f1ee733d8f87a70def3bf213e52a1125fa)\n\n#### [v0.1.1](https://github.com/kremalicious/gatsby-plugin-matomo/compare/v0.1.0...v0.1.1)\n\n> 7 May 2018\n\n- link up readme badges [`6793592`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/6793592ed28e23177ad0450874ebba055d912dc2)\n- Release 0.1.1 [`48c73ff`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/48c73ff2415dd25ce85924cdd53056b8f561face)\n- docs(readme): add Greenkeeper badge [`ec73329`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/ec73329dd2ad383aa380ed57667da7a7019824a1)\n\n#### v0.1.0\n\n> 7 May 2018\n\n- initial commit 🍹 [`49bffd3`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/49bffd3cf18f1ba9e099048f9a5591f9200f3296)\n- add Travis, add badges, add semi-auto releases [`fe823b7`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/fe823b76a18a5310e3cd19965b9f61e02774f7e0)\n- Release 0.1.0 [`09739a7`](https://github.com/kremalicious/gatsby-plugin-matomo/commit/09739a72c5c2e08b0a74faba8bc4cfb03fdac220)\n" + } + } + }, + { + "node": { + "name": "portfolio", + "url": "https://github.com/kremalicious/portfolio", + "owner": { + "login": "kremalicious" + }, + "object": null + } + }, + { + "node": { + "name": "gatsby-redirect-from", + "url": "https://github.com/kremalicious/gatsby-redirect-from", + "owner": { + "login": "kremalicious" + }, + "object": { + "id": "MDQ6QmxvYjE0NjY2ODk3NDo1YmVmMzg0N2ZlZThjMTk3NThiYThmMjBiMzE3NDFmN2I0YTcwZGU4", + "text": "### Changelog\n\nAll notable changes to this project will be documented in this file. Dates are displayed in UTC.\n\nGenerated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).\n\n#### [v0.2.1](https://github.com/kremalicious/gatsby-redirect-from/compare/v0.2.0...v0.2.1)\n\n> 10 June 2019\n\n- fix auto changelog [`bba9f39`](https://github.com/kremalicious/gatsby-redirect-from/commit/bba9f3915511193384863b61b28b3c7f36d1007f)\n\n#### [v0.2.0](https://github.com/kremalicious/gatsby-redirect-from/compare/v0.1.1...v0.2.0)\n\n> 10 June 2019\n\n- Update docs & dependencies [`#12`](https://github.com/kremalicious/gatsby-redirect-from/pull/12)\n- specify node 8 instead of 10 as engine [`#11`](https://github.com/kremalicious/gatsby-redirect-from/pull/11)\n- Support alternative markdown queries (such as allMdx) [`#10`](https://github.com/kremalicious/gatsby-redirect-from/pull/10)\n- Update release-it to the latest version 🚀 [`#8`](https://github.com/kremalicious/gatsby-redirect-from/pull/8)\n- update docs, mention new options [`07835d8`](https://github.com/kremalicious/gatsby-redirect-from/commit/07835d8405854a4e5a190a6eeeb252604aaaddb7)\n- simplify release-it tasks, add changelog [`3ec4ccf`](https://github.com/kremalicious/gatsby-redirect-from/commit/3ec4ccfb8e19032068fd34c24929179a5237f0ca)\n- add prettier [`3f33f65`](https://github.com/kremalicious/gatsby-redirect-from/commit/3f33f65430126e634f498629e6be8437c6f1ed7b)\n\n#### [v0.1.1](https://github.com/kremalicious/gatsby-redirect-from/compare/v0.1.0...v0.1.1)\n\n> 30 August 2018\n\n- integrate with gatsby-plugin-meta-redirect, notes on server rendering [`2cd07ee`](https://github.com/kremalicious/gatsby-redirect-from/commit/2cd07ee33e2c267b3783630c6e5cfbdb6fb57c4b)\n- Release 0.1.1 [`e72d5ab`](https://github.com/kremalicious/gatsby-redirect-from/commit/e72d5aba5474104d34c99fcc5880a39c02696918)\n\n#### [v0.1.0](https://github.com/kremalicious/gatsby-redirect-from/compare/v0.0.3...v0.1.0)\n\n> 30 August 2018\n\n- babelify build [`#5`](https://github.com/kremalicious/gatsby-redirect-from/pull/5)\n- clarify prerequisites [`139a4af`](https://github.com/kremalicious/gatsby-redirect-from/commit/139a4afc1d81fee444a6bf0c4775c63aea4e7c09)\n- Release 0.1.0 [`9bd28a7`](https://github.com/kremalicious/gatsby-redirect-from/commit/9bd28a7e9cc3cfa83e3b5b7606b08d3cb26fafe0)\n- add npm badge [`53043c8`](https://github.com/kremalicious/gatsby-redirect-from/commit/53043c82f86dfd2e17c1ca0ec4580441baeb6d8d)\n\n#### [v0.0.3](https://github.com/kremalicious/gatsby-redirect-from/compare/v0.0.2...v0.0.3)\n\n> 29 August 2018\n\n- fix publish [`c91a362`](https://github.com/kremalicious/gatsby-redirect-from/commit/c91a3626390bfa632322007300818e58a25d75d0)\n- Release 0.0.3 [`f1d4982`](https://github.com/kremalicious/gatsby-redirect-from/commit/f1d4982d2424beb67119702a8181d4284ffe399e)\n\n#### v0.0.2\n\n> 29 August 2018\n\n- Add Greenkeeper badge 🌴 [`#1`](https://github.com/kremalicious/gatsby-redirect-from/pull/1)\n- initial commit 🍷 [`dfb3bb0`](https://github.com/kremalicious/gatsby-redirect-from/commit/dfb3bb0954b1933c4d9e36ebc8cb302a0dc70795)\n- Release 0.0.2 [`6924e7b`](https://github.com/kremalicious/gatsby-redirect-from/commit/6924e7b2d9d00a6eb6a03eeb328f29d561dbf904)\n- fix test [`b0129a5`](https://github.com/kremalicious/gatsby-redirect-from/commit/b0129a5ee73d292422a2f7746412aa55a0ce1097)\n" + } + } + } + ] + } + } + } +} diff --git a/jest/__fixtures__/meta.json b/jest/__fixtures__/meta.json new file mode 100644 index 00000000..e8b54831 --- /dev/null +++ b/jest/__fixtures__/meta.json @@ -0,0 +1,39 @@ +{ + "site": { + "siteMetadata": { + "siteTitle": "kremalicious", + "siteTitleShort": "krlc", + "siteDescription": "Blog of designer & developer Matthias Kretschmann", + "siteUrl": "https://kremalicious.com", + "author": { + "name": "Matthias Kretschmann", + "email": "m@kretschmann.io", + "uri": "https://matthiaskretschmann.com", + "twitter": "https://twitter.com/kremalicious", + "github": "https://github.com/kremalicious", + "facebook": "https://facebook.com/matthiaskretschmann", + "bitcoin": "171qDmKEXm9YBgBLXyGjjPvopP5o9htQ1V", + "ether": "0x339dbC44d39bf1961E385ed0Ae88FC6069b87Ea1" + }, + "typekitID": "msu4qap", + "menu": [ + { + "title": "Photos", + "link": "/photos" + }, + { + "title": "Goodies", + "link": "/tags/goodies" + }, + { + "title": "Tags", + "link": "/tags" + } + ], + "rss": "/feed.xml", + "jsonfeed": "/feed.json", + "itemsPerPage": 20, + "repoContentPath": "https://github.com/kremalicious/blog/tree/master/content" + } + } +} diff --git a/jest/__fixtures__/photos.json b/jest/__fixtures__/photos.json new file mode 100644 index 00000000..3de6a58f --- /dev/null +++ b/jest/__fixtures__/photos.json @@ -0,0 +1,62 @@ +{ + "photos": { + "edges": [ + { + "node": { + "id": "6effe45d-0884-527c-9fba-6f7f567979fd", + "frontmatter": { + "title": "Országház II", + "type": "photo", + "image": { + "childImageSharp": { + "fluid": { + "aspectRatio": 1, + "src": "/static/2dbcf257b4bdf625c24fede935d32425/2423a/2019-11-03-orszaghaz-ii.jpg", + "srcSet": "/static/2dbcf257b4bdf625c24fede935d32425/b7835/2019-11-03-orszaghaz-ii.jpg 100w,\n/static/2dbcf257b4bdf625c24fede935d32425/2de44/2019-11-03-orszaghaz-ii.jpg 200w,\n/static/2dbcf257b4bdf625c24fede935d32425/2423a/2019-11-03-orszaghaz-ii.jpg 400w,\n/static/2dbcf257b4bdf625c24fede935d32425/66039/2019-11-03-orszaghaz-ii.jpg 600w,\n/static/2dbcf257b4bdf625c24fede935d32425/ba820/2019-11-03-orszaghaz-ii.jpg 800w,\n/static/2dbcf257b4bdf625c24fede935d32425/d04d5/2019-11-03-orszaghaz-ii.jpg 3793w", + "srcWebp": "/static/2dbcf257b4bdf625c24fede935d32425/33771/2019-11-03-orszaghaz-ii.webp", + "srcSetWebp": "/static/2dbcf257b4bdf625c24fede935d32425/4f5da/2019-11-03-orszaghaz-ii.webp 100w,\n/static/2dbcf257b4bdf625c24fede935d32425/72345/2019-11-03-orszaghaz-ii.webp 200w,\n/static/2dbcf257b4bdf625c24fede935d32425/33771/2019-11-03-orszaghaz-ii.webp 400w,\n/static/2dbcf257b4bdf625c24fede935d32425/f12d8/2019-11-03-orszaghaz-ii.webp 600w,\n/static/2dbcf257b4bdf625c24fede935d32425/b975c/2019-11-03-orszaghaz-ii.webp 800w,\n/static/2dbcf257b4bdf625c24fede935d32425/f7332/2019-11-03-orszaghaz-ii.webp 3793w", + "sizes": "(max-width: 400px) 100vw, 400px", + "originalImg": "/static/2dbcf257b4bdf625c24fede935d32425/d04d5/2019-11-03-orszaghaz-ii.jpg", + "originalName": "2019-11-03-orszaghaz-ii.jpg", + "presentationWidth": 400, + "presentationHeight": 300 + } + } + } + }, + "fields": { + "slug": "/orszaghaz-ii/" + } + } + }, + { + "node": { + "id": "c80697e5-681d-5fcc-9dab-c3a3821ff0b1", + "frontmatter": { + "title": "Országház I", + "type": "photo", + "image": { + "childImageSharp": { + "fluid": { + "aspectRatio": 1, + "src": "/static/36d87329aeeda296ae923606e5a4a785/2423a/2019-11-02-orszaghaz-i.jpg", + "srcSet": "/static/36d87329aeeda296ae923606e5a4a785/b7835/2019-11-02-orszaghaz-i.jpg 100w,\n/static/36d87329aeeda296ae923606e5a4a785/2de44/2019-11-02-orszaghaz-i.jpg 200w,\n/static/36d87329aeeda296ae923606e5a4a785/2423a/2019-11-02-orszaghaz-i.jpg 400w,\n/static/36d87329aeeda296ae923606e5a4a785/66039/2019-11-02-orszaghaz-i.jpg 600w,\n/static/36d87329aeeda296ae923606e5a4a785/ba820/2019-11-02-orszaghaz-i.jpg 800w,\n/static/36d87329aeeda296ae923606e5a4a785/c9c86/2019-11-02-orszaghaz-i.jpg 3708w", + "srcWebp": "/static/36d87329aeeda296ae923606e5a4a785/33771/2019-11-02-orszaghaz-i.webp", + "srcSetWebp": "/static/36d87329aeeda296ae923606e5a4a785/4f5da/2019-11-02-orszaghaz-i.webp 100w,\n/static/36d87329aeeda296ae923606e5a4a785/72345/2019-11-02-orszaghaz-i.webp 200w,\n/static/36d87329aeeda296ae923606e5a4a785/33771/2019-11-02-orszaghaz-i.webp 400w,\n/static/36d87329aeeda296ae923606e5a4a785/f12d8/2019-11-02-orszaghaz-i.webp 600w,\n/static/36d87329aeeda296ae923606e5a4a785/b975c/2019-11-02-orszaghaz-i.webp 800w,\n/static/36d87329aeeda296ae923606e5a4a785/262c1/2019-11-02-orszaghaz-i.webp 3708w", + "sizes": "(max-width: 400px) 100vw, 400px", + "originalImg": "/static/36d87329aeeda296ae923606e5a4a785/c9c86/2019-11-02-orszaghaz-i.jpg", + "originalName": "2019-11-02-orszaghaz-i.jpg", + "presentationWidth": 400, + "presentationHeight": 297 + } + } + } + }, + "fields": { + "slug": "/orszaghaz-i/" + } + } + } + ] + } +} diff --git a/jest/__fixtures__/post.json b/jest/__fixtures__/post.json new file mode 100644 index 00000000..54821d04 --- /dev/null +++ b/jest/__fixtures__/post.json @@ -0,0 +1,41 @@ +{ + "post": { + "html": "

There are many reasons you might want to browse anonymously which can be accomplished by using Tor. The setup instructions on Tor’s website are quite scattered and outdated so here are some steps to setup Tor on macOS with a simple automated script at the end.

\n

I’m using macOS Catalina (10.15) for the following instructions but it should work on almost any macOS version.

\n

#Tor Browser

\n

\n \n \n \n \n
Tor Browser
\n

\n

The most simple way to surf anonymously with Tor is to just grab Tor Browser. It’s a modified version of Firefox Extended Support Release (ESR) with Tor and some extensions (Torbutton, TorLauncher, NoScript, and HTTPS-Everywhere) built right in. Upon start, Tor Browser automatically starts the required Tor background processes and routes traffic through the Tor network. That’s the way to go if you want the highest level of protection without much further configuration.

\n

But it’s based on an older version of Firefox and there might be more you want to do anonymously on your machine than just browsing the web, like accessing resources via the Terminal or any other app. Or just use the browser you’re used to.

\n

For this you need to have Tor installed on your system and additionally set specific proxy values in your network preferences after you’ve started Tor.

\n
\n

Be aware that the instructions and the script mentioned below will not make whatever you do on the web anonymous. Much depends on your browsing habits, what apps you're using, and none of the methods below will offer the same level of protection than Tor Browser out of the box. You have been warned.

\n
\n

#Install Tor

\n

Contrary to the weirdly outdated install instructions on Tor’s website (hey, remember Macports?), installing Tor on macOS is super simple with Homebrew.

\n

In your Terminal execute:

\n
brew install tor
\n

Then you can start it up by running:

\n
tor
\n

Congratulations, you now have Tor running on your system. But none of your network traffic is routed through it yet.

\n

In order for all your system traffic being routed through Tor you need to adjust your system’s network proxy settings which you can either do visually in the System Preferences or programmatically via macOS’s builtin networksetup.

\n

#Set network proxy settings via System Preferences

\n

You can do this under System Preferences > Network by creating a specific Tor network location for it:

\n
    \n
  1. From Location dropdown at the top, select Edit Locations…
  2. \n
  3. Create a new location by hitting the plus button and name it Tor. Hitting Done will select the new location which is now ready to be configured.
  4. \n
  5. Go to Advanced > Proxies and activate SOCKS Proxy and add those values:
  6. \n
  7. SOCKS proxy server: localhost
  8. \n
  9. Port: 9050
  10. \n
\n

\n \n \n \n \n
Network Settings
\n

\n

After hitting OK & Apply at the initial network screen, you can easily switch to this newly created location from your menu bar under  > Location whenever you start up Tor.

\n

Switching to the Tor location routes all network traffic on your system through Tor. Note that you have to repeat those steps for every other network interface if you use, say, Wi-Fi and Ethernet interchangeably.

\n

#All in one go: start Tor & set network proxy settings automatically

\n

When you’re already in the Terminal to start up Tor, additionally setting the network settings involves a lot of fiddling around. Ain’t nobody got time for that.

\n

Thankfully macOS provides a way to programmatically set those proxy values via the networksetup utility. I’ve found a nice script for this but running it opened multiple admin password prompts. So I extended it a bit to make it more user friendly.

\n

In a nutshell, this shell script asks you for your admin password upfront, starts up Tor, and sets all required proxy network settings automatically:

\n
#!/usr/bin/env bash\n\n# 'Wi-Fi' or 'Ethernet' or 'Display Ethernet'\nINTERFACE=Wi-Fi\n\n# Ask for the administrator password upfront\nsudo -v\n\n# Keep-alive: update existing `sudo` time stamp until finished\nwhile true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &\n\n# trap ctrl-c and call disable_proxy()\nfunction disable_proxy() {\n    sudo networksetup -setsocksfirewallproxystate $INTERFACE off\n    echo "$(tput setaf 64)" #green\n    echo "SOCKS proxy disabled."\n    echo "$(tput sgr0)" # color reset\n}\ntrap disable_proxy INT\n\n# Let's roll\nsudo networksetup -setsocksfirewallproxy $INTERFACE 127.0.0.1 9050 off\nsudo networksetup -setsocksfirewallproxystate $INTERFACE on\n\necho "$(tput setaf 64)" # green\necho "SOCKS proxy 127.0.0.1:9050 enabled."\necho "$(tput setaf 136)" # orange\necho "Starting Tor..."\necho "$(tput sgr0)" # color reset\n\ntor
\n

Save this script under something like tor.sh in one of your sourced bin folders, make it executable with chmod + x and use it as a replacement for the general tor command. So you can just run

\n
tor.sh
\n

and Tor should run smoothly on your system without additional configuration:

\n

\n \n \n \n \n
Tor running in Terminal
\n

\n

Verify you’re indeed browsing over the Tor network by going to check.torproject.org.

\n

When you’re done, just exit the script with ctrl + c and the network settings will be reverted to their previous configuration.

\n

#Non-standard apps

\n

Some apps are just not good Mac citizens and use their own network settings, ignoring macOS system network proxy settings. E.g. older versions of Google Chrome were using their own custom network settings and therefore were not routing their web traffic through the proxy configured in System Preferences.

\n

But the most recent Chrome version automatically picks up macOS’s native proxy settings, as does the most recent version of Firefox.

\n

Always check your Tor connection with whatever app you’re using and if needed set the proxy preferences manually in the respective app with:

\n\n", + "excerpt": "There are many reasons you might want to browse anonymously which can be accomplished by using Tor. The setup instructions on Tor’s website…", + "frontmatter": { + "type": "post", + "title": "Simple Tor setup on macOS", + "image": { + "childImageSharp": { + "fluid": { + "aspectRatio": 3.2, + "src": "/static/c87c817b4191fb48e9ca4419c0c70bb8/3995d/teaser-tor.png", + "srcSet": "/static/c87c817b4191fb48e9ca4419c0c70bb8/f0031/teaser-tor.png 200w,\n/static/c87c817b4191fb48e9ca4419c0c70bb8/cad89/teaser-tor.png 400w,\n/static/c87c817b4191fb48e9ca4419c0c70bb8/3995d/teaser-tor.png 800w,\n/static/c87c817b4191fb48e9ca4419c0c70bb8/32ce4/teaser-tor.png 1200w,\n/static/c87c817b4191fb48e9ca4419c0c70bb8/1ed7e/teaser-tor.png 1600w,\n/static/c87c817b4191fb48e9ca4419c0c70bb8/19dc3/teaser-tor.png 1920w", + "srcWebp": "/static/c87c817b4191fb48e9ca4419c0c70bb8/240ac/teaser-tor.webp", + "srcSetWebp": "/static/c87c817b4191fb48e9ca4419c0c70bb8/04c4c/teaser-tor.webp 200w,\n/static/c87c817b4191fb48e9ca4419c0c70bb8/ebea1/teaser-tor.webp 400w,\n/static/c87c817b4191fb48e9ca4419c0c70bb8/240ac/teaser-tor.webp 800w,\n/static/c87c817b4191fb48e9ca4419c0c70bb8/823f0/teaser-tor.webp 1200w,\n/static/c87c817b4191fb48e9ca4419c0c70bb8/9e49e/teaser-tor.webp 1600w,\n/static/c87c817b4191fb48e9ca4419c0c70bb8/68ae1/teaser-tor.webp 1920w", + "sizes": "(max-width: 800px) 100vw, 800px", + "originalImg": "/static/c87c817b4191fb48e9ca4419c0c70bb8/19dc3/teaser-tor.png", + "originalName": "teaser-tor.png", + "presentationWidth": 800, + "presentationHeight": 250 + } + }, + "fields": null + }, + "toc": true, + "author": "Matthias Kretschmann", + "updated": "2019-11-07T22:52:46.000Z", + "tags": ["tutorial", "tor", "macos", "goodies", "apple"], + "linkurl": null, + "style": null, + "changelog": null + }, + "fields": { + "slug": "/simple-tor-setup-on-mac-os-x", + "date": "2015-08-02T19:57:30.912Z", + "githubLink": "https://github.com/kremalicious/blog/tree/master/content/posts/2015-08-02-simple-tor-setup-on-mac-os-x/index.md" + }, + "rawMarkdownBody": "\nThere are many reasons you might want to browse anonymously which can be accomplished by using [Tor](https://www.torproject.org). The setup instructions on Tor's website are quite scattered and outdated so here are some steps to setup Tor on macOS with a simple automated script at the end.\n\nI'm using macOS Catalina (10.15) for the following instructions but it should work on almost any macOS version.\n\n## Tor Browser\n\n![Tor Browser](tor-browser.png)\n\nThe most simple way to surf anonymously with Tor is to just grab [Tor Browser](https://www.torproject.org/projects/torbrowser.html.en). It's a modified version of [Firefox Extended Support Release (ESR)](https://www.mozilla.org/en-US/firefox/organizations/) with Tor and some extensions (Torbutton, TorLauncher, NoScript, and HTTPS-Everywhere) built right in. Upon start, Tor Browser automatically starts the required Tor background processes and routes traffic through the Tor network. That's the way to go if you want the highest level of protection without much further configuration.\n\nBut it's based on an older version of Firefox and there might be more you want to do anonymously on your machine than just browsing the web, like accessing resources via the Terminal or any other app. Or just use the browser you're used to.\n\nFor this you need to have Tor installed on your system and additionally set specific proxy values in your network preferences after you've started Tor.\n\n
\n

Be aware that the instructions and the script mentioned below will not make whatever you do on the web anonymous. Much depends on your browsing habits, what apps you're using, and none of the methods below will offer the same level of protection than Tor Browser out of the box. You have been warned.

\n
\n\n## Install Tor\n\nContrary to the weirdly outdated [install instructions on Tor's website](https://www.torproject.org/docs/tor-doc-osx.html.en) (hey, remember Macports?), installing Tor on macOS is super simple with [Homebrew](http://brew.sh).\n\nIn your Terminal execute:\n\n```bash\nbrew install tor\n```\n\nThen you can start it up by running:\n\n```bash\ntor\n```\n\nCongratulations, you now have Tor running on your system. But none of your network traffic is routed through it yet.\n\nIn order for all your system traffic being routed through Tor you need to adjust your system's network proxy settings which you can either do visually in the System Preferences or programmatically via macOS's builtin `networksetup`.\n\n## Set network proxy settings via System Preferences\n\nYou can do this under _System Preferences > Network_ by creating a specific Tor network location for it:\n\n1. From Location dropdown at the top, select _Edit Locations..._\n2. Create a new location by hitting the plus button and name it _Tor_. Hitting Done will select the new location which is now ready to be configured.\n3. Go to _Advanced > Proxies_ and activate _SOCKS Proxy_ and add those values:\n\n- _SOCKS proxy server_: `localhost`\n- _Port_: `9050`\n\n![Network Settings](tor-osx-proxy.png)\n\nAfter hitting _OK_ & _Apply_ at the initial network screen, you can easily switch to this newly created location from your menu bar under _ > Location_ whenever you start up Tor.\n\nSwitching to the Tor location routes all network traffic on your system through Tor. Note that you have to repeat those steps for every other network interface if you use, say, Wi-Fi and Ethernet interchangeably.\n\n## All in one go: start Tor & set network proxy settings automatically\n\nWhen you're already in the Terminal to start up Tor, additionally setting the network settings involves a lot of fiddling around. Ain't nobody got time for that.\n\nThankfully macOS provides a way to programmatically set those proxy values via the `networksetup` utility. I've found a [nice script](http://leonid.shevtsov.me/en/an-easy-way-to-use-tor-on-os-x) for this but running it opened multiple admin password prompts. So I extended it a bit to make it more user friendly.\n\nIn a nutshell, this shell script asks you for your admin password upfront, starts up Tor, and sets all required proxy network settings automatically:\n\n```bash\n#!/usr/bin/env bash\n\n# 'Wi-Fi' or 'Ethernet' or 'Display Ethernet'\nINTERFACE=Wi-Fi\n\n# Ask for the administrator password upfront\nsudo -v\n\n# Keep-alive: update existing `sudo` time stamp until finished\nwhile true; do sudo -n true; sleep 60; kill -0 \"$$\" || exit; done 2>/dev/null &\n\n# trap ctrl-c and call disable_proxy()\nfunction disable_proxy() {\n sudo networksetup -setsocksfirewallproxystate $INTERFACE off\n echo \"$(tput setaf 64)\" #green\n echo \"SOCKS proxy disabled.\"\n echo \"$(tput sgr0)\" # color reset\n}\ntrap disable_proxy INT\n\n# Let's roll\nsudo networksetup -setsocksfirewallproxy $INTERFACE 127.0.0.1 9050 off\nsudo networksetup -setsocksfirewallproxystate $INTERFACE on\n\necho \"$(tput setaf 64)\" # green\necho \"SOCKS proxy 127.0.0.1:9050 enabled.\"\necho \"$(tput setaf 136)\" # orange\necho \"Starting Tor...\"\necho \"$(tput sgr0)\" # color reset\n\ntor\n```\n\nSave this script under something like `tor.sh` in one of your sourced `bin` folders, make it executable with `chmod + x` and use it as a replacement for the general `tor` command. So you can just run\n\n```bash\ntor.sh\n```\n\nand Tor should run smoothly on your system without additional configuration:\n\n![Tor running in Terminal](tor-osx-terminal.png)\n\nVerify you're indeed browsing over the Tor network by going to [check.torproject.org](https://check.torproject.org).\n\nWhen you're done, just exit the script with ctrl + c and the network settings will be reverted to their previous configuration.\n\n## Non-standard apps\n\nSome apps are just not good Mac citizens and use their own network settings, ignoring macOS system network proxy settings. E.g. older versions of Google Chrome were using their own custom network settings and therefore were not routing their web traffic through the proxy configured in System Preferences.\n\nBut the most recent Chrome version automatically picks up macOS's native proxy settings, as does the most recent version of Firefox.\n\nAlways [check](https://check.torproject.org) your Tor connection with whatever app you're using and if needed set the proxy preferences manually in the respective app with:\n\n- _SOCKS proxy server_: `localhost`\n- _Port_: `9050`\n", + "tableOfContents": "" + } +} diff --git a/jest/__fixtures__/posts.json b/jest/__fixtures__/posts.json new file mode 100644 index 00000000..99d2e9c8 --- /dev/null +++ b/jest/__fixtures__/posts.json @@ -0,0 +1,118 @@ +{ + "allMarkdownRemark": { + "edges": [ + { + "node": { + "id": "6effe45d-0884-527c-9fba-6f7f567979fd", + "fileAbsolutePath": "/Users/m/Code/blog/content/photos/2019-11-03-orszaghaz-ii.md", + "html": "

Inside the Hungarian Parliament Building in Budapest, Hungary.

", + "excerpt": "Inside the Hungarian Parliament Building in Budapest, Hungary.", + "frontmatter": { + "title": "Országház II", + "type": "photo", + "linkurl": null, + "tags": null, + "image": { + "childImageSharp": { + "original": { + "src": "/static/2019-11-03-orszaghaz-ii-2dbcf257b4bdf625c24fede935d32425.jpg" + }, + "fluid": { + "aspectRatio": 2.3255813953488373, + "src": "/static/2dbcf257b4bdf625c24fede935d32425/ef7a0/2019-11-03-orszaghaz-ii.jpg", + "srcSet": "/static/2dbcf257b4bdf625c24fede935d32425/23780/2019-11-03-orszaghaz-ii.jpg 100w,\n/static/2dbcf257b4bdf625c24fede935d32425/02ed9/2019-11-03-orszaghaz-ii.jpg 200w,\n/static/2dbcf257b4bdf625c24fede935d32425/ef7a0/2019-11-03-orszaghaz-ii.jpg 400w,\n/static/2dbcf257b4bdf625c24fede935d32425/ac974/2019-11-03-orszaghaz-ii.jpg 600w,\n/static/2dbcf257b4bdf625c24fede935d32425/12c26/2019-11-03-orszaghaz-ii.jpg 800w,\n/static/2dbcf257b4bdf625c24fede935d32425/24914/2019-11-03-orszaghaz-ii.jpg 3793w", + "srcWebp": "/static/2dbcf257b4bdf625c24fede935d32425/a93fc/2019-11-03-orszaghaz-ii.webp", + "srcSetWebp": "/static/2dbcf257b4bdf625c24fede935d32425/b0720/2019-11-03-orszaghaz-ii.webp 100w,\n/static/2dbcf257b4bdf625c24fede935d32425/f6188/2019-11-03-orszaghaz-ii.webp 200w,\n/static/2dbcf257b4bdf625c24fede935d32425/a93fc/2019-11-03-orszaghaz-ii.webp 400w,\n/static/2dbcf257b4bdf625c24fede935d32425/7c0bb/2019-11-03-orszaghaz-ii.webp 600w,\n/static/2dbcf257b4bdf625c24fede935d32425/d1e4e/2019-11-03-orszaghaz-ii.webp 800w,\n/static/2dbcf257b4bdf625c24fede935d32425/0a478/2019-11-03-orszaghaz-ii.webp 3793w", + "sizes": "(max-width: 400px) 100vw, 400px", + "originalImg": "/static/2dbcf257b4bdf625c24fede935d32425/24914/2019-11-03-orszaghaz-ii.jpg", + "originalName": "2019-11-03-orszaghaz-ii.jpg", + "presentationWidth": 400, + "presentationHeight": 300 + } + } + } + }, + "fields": { + "slug": "/orszaghaz-ii/", + "date": "November 03, 2019" + } + } + }, + { + "node": { + "id": "c80697e5-681d-5fcc-9dab-c3a3821ff0b1", + "fileAbsolutePath": "/Users/m/Code/blog/content/photos/2019-11-02-orszaghaz-i.md", + "html": "

The Hungarian Parliament Building seen from across the Danube in Budapest, Hungary.

", + "excerpt": "The Hungarian Parliament Building seen from across the Danube in Budapest, Hungary.", + "frontmatter": { + "title": "Országház I", + "type": "photo", + "linkurl": null, + "tags": null, + "featured": true, + "image": { + "childImageSharp": { + "original": { + "src": "/static/2019-11-02-orszaghaz-i-36d87329aeeda296ae923606e5a4a785.jpg" + }, + "fluid": { + "aspectRatio": 2.3255813953488373, + "src": "/static/36d87329aeeda296ae923606e5a4a785/ef7a0/2019-11-02-orszaghaz-i.jpg", + "srcSet": "/static/36d87329aeeda296ae923606e5a4a785/23780/2019-11-02-orszaghaz-i.jpg 100w,\n/static/36d87329aeeda296ae923606e5a4a785/02ed9/2019-11-02-orszaghaz-i.jpg 200w,\n/static/36d87329aeeda296ae923606e5a4a785/ef7a0/2019-11-02-orszaghaz-i.jpg 400w,\n/static/36d87329aeeda296ae923606e5a4a785/ac974/2019-11-02-orszaghaz-i.jpg 600w,\n/static/36d87329aeeda296ae923606e5a4a785/12c26/2019-11-02-orszaghaz-i.jpg 800w,\n/static/36d87329aeeda296ae923606e5a4a785/b9e8b/2019-11-02-orszaghaz-i.jpg 3708w", + "srcWebp": "/static/36d87329aeeda296ae923606e5a4a785/a93fc/2019-11-02-orszaghaz-i.webp", + "srcSetWebp": "/static/36d87329aeeda296ae923606e5a4a785/b0720/2019-11-02-orszaghaz-i.webp 100w,\n/static/36d87329aeeda296ae923606e5a4a785/f6188/2019-11-02-orszaghaz-i.webp 200w,\n/static/36d87329aeeda296ae923606e5a4a785/a93fc/2019-11-02-orszaghaz-i.webp 400w,\n/static/36d87329aeeda296ae923606e5a4a785/7c0bb/2019-11-02-orszaghaz-i.webp 600w,\n/static/36d87329aeeda296ae923606e5a4a785/d1e4e/2019-11-02-orszaghaz-i.webp 800w,\n/static/36d87329aeeda296ae923606e5a4a785/730f8/2019-11-02-orszaghaz-i.webp 3708w", + "sizes": "(max-width: 400px) 100vw, 400px", + "originalImg": "/static/36d87329aeeda296ae923606e5a4a785/b9e8b/2019-11-02-orszaghaz-i.jpg", + "originalName": "2019-11-02-orszaghaz-i.jpg", + "presentationWidth": 400, + "presentationHeight": 297 + } + } + } + }, + "fields": { + "slug": "/orszaghaz-i/", + "date": "November 02, 2019" + } + } + }, + { + "node": { + "id": "2e2c9611-be7b-5bc0-a72b-6c63e2072b5a", + "fileAbsolutePath": "/Users/m/Code/blog/content/posts/2019-10-24-ocean-protocol-and-ipfs-sitting-in-the-merkle-tree/index.md", + "html": "

IPFS is now integrated into the Ocean Protocol stack, allowing you to take advantage of decentralized asset file hosting.

\n
\n
\n

This article was originally posted on Medium in the Ocean Protocol blog.

\n
\n
\n

#✨ Going Decentralized

\n

With Ocean Protocol, you can use centralized storage services like S3, Azure Storage, or your own On-Premise storage to store and retrieve your asset files through Osmosis drivers in Brizo.

\n

But storing asset files in a centralized service poses multiple problems:

\n\n

Initially created to store and efficiently move scientific data sets, the InterPlanetary File System (IPFS) solves all those issues with its goal of transforming the vastly centralized web into a distributed peer-to-peer network.

\n

Files are distributed among multiple nodes, eliminating the single point of failure, legal, and censorship issues. By using content-based instead of location-based addressing of files, URLs won’t break if files are moved.

\n

So we defined OEP-15 to make the ipfs:// protocol a first-class citizen in the Ocean Protocol stack, allowing you to store asset files on IPFS, and use their native IPFS URLs during the publish process.

\n\n

In short, every component in the Ocean Protocol stack now supports publishing and consuming of asset files stored in IPFS which includes support for native IPFS URLs, referencing files with their Content Identifiers (CIDs).

\n

#⛲️ IPFS in Commons Marketplace

\n

Every file stored on IPFS is public by default, so it made perfect sense using this in our Commons Marketplace first. We went through multiple prototypes to end up with our final setup.

\n

During the publish flow you will find an extended Files section for adding a file from an existing URL, and for adding a local file from your device to IPFS.

\n

\n \n \n + React.createElement('a', { + ...rest, + href: to + }) + ), + StaticQuery: jest.fn(), + useStaticQuery: jest.fn() +} diff --git a/jest/__mocks__/gatsby.ts b/jest/__mocks__/gatsby.ts deleted file mode 100644 index ee8e8621..00000000 --- a/jest/__mocks__/gatsby.ts +++ /dev/null @@ -1,14 +0,0 @@ -import React from 'react' -const gatsby = jest.requireActual('gatsby') - -export default { - ...gatsby, - graphql: jest.fn(), - Link: jest - .fn() - .mockImplementation(({ to, ...rest }) => - React.createElement('a', { ...rest, href: to }) - ), - StaticQuery: jest.fn(), - useStaticQuery: jest.fn() -} diff --git a/jest/__mocks__/svgr-mock.js b/jest/__mocks__/svgr-mock.js new file mode 100644 index 00000000..c1faa04d --- /dev/null +++ b/jest/__mocks__/svgr-mock.js @@ -0,0 +1,6 @@ +import React from 'react' + +export default 'SvgrURL' +const SvgrMock = React.forwardRef((props, ref) => ) + +export const ReactComponent = SvgrMock diff --git a/jest/__mocks__/svgr-mock.ts b/jest/__mocks__/svgr-mock.ts deleted file mode 100644 index 13b64e5a..00000000 --- a/jest/__mocks__/svgr-mock.ts +++ /dev/null @@ -1,3 +0,0 @@ -const content = 'svg' -export const ReactComponent = content -export default content diff --git a/jest/setup-test-env.ts b/jest/setup-test-env.ts index 264828a9..099876c7 100644 --- a/jest/setup-test-env.ts +++ b/jest/setup-test-env.ts @@ -1 +1,18 @@ import '@testing-library/jest-dom/extend-expect' + +import * as Gatsby from 'gatsby' +const useStaticQuery = jest.spyOn(Gatsby, 'useStaticQuery') +import meta from '../jest/__fixtures__/meta.json' +import avatar from '../jest/__fixtures__/avatar.json' +import posts from '../jest/__fixtures__/posts.json' +import github from '../jest/__fixtures__/github.json' + +beforeAll(() => { + useStaticQuery.mockImplementation(() => ({ + ...meta, + ...avatar, + logo: { edges: [{ node: { relativePath: 'apple-touch-icon.png' } }] }, + ...posts, + ...github + })) +}) diff --git a/package.json b/package.json index 4fdc9952..2e4a6002 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "start": "gatsby develop --host 0.0.0.0", "build": "gatsby build && npm run copy", "ssr": "npm run build && serve -s public/", - "test": "npm run lint && jest --coverage", + "test": "npm run lint && jest --coverage --silent", "test:watch": "npm run lint && jest --coverage --watch", "copy": "cp -R content/media/ public", "lint": "run-p --continue-on-error lint:js lint:css lint:md", diff --git a/src/@types/Image.d.ts b/src/@types/Image.d.ts index 338c3b3a..e6de4a07 100644 --- a/src/@types/Image.d.ts +++ b/src/@types/Image.d.ts @@ -4,7 +4,7 @@ export interface ImageProps { title?: string fluid?: FluidObject fixed?: FixedObject - alt: string + alt?: string original?: { src: string } } diff --git a/src/components/Layout.test.tsx b/src/components/Layout.test.tsx new file mode 100644 index 00000000..649255fb --- /dev/null +++ b/src/components/Layout.test.tsx @@ -0,0 +1,7 @@ +import React from 'react' +import testRender from '../../jest/testRender' +import Layout from './Layout' + +describe('Layout', () => { + testRender(Hello) +}) diff --git a/src/components/atoms/Changelog.test.tsx b/src/components/atoms/Changelog.test.tsx index 3651523c..00fe8e35 100644 --- a/src/components/atoms/Changelog.test.tsx +++ b/src/components/atoms/Changelog.test.tsx @@ -1,23 +1,17 @@ import React from 'react' -import testRender from '../../../jest/testRender' +import { render } from '@testing-library/react' -import { PureChangelog as Changelog } from './Changelog' -import { GitHubRepo } from '../../@types/GitHub' - -const repos: [{ node: GitHubRepo }] = [ - { - node: { - name: 'gatsby-plugin-matomo', - url: 'https://hello.com', - owner: { login: 'kremalicious' }, - object: { - id: 'hello', - text: 'hello' - } - } - } -] +import Changelog from './Changelog' describe('Changelog', () => { - testRender() + it('renders without crashing', () => { + const { container, rerender } = render( + + ) + expect(container.firstChild).toBeInTheDocument() + + // return nothing when no match + rerender() + expect(container.firstChild).not.toBeInTheDocument() + }) }) diff --git a/src/components/atoms/Changelog.tsx b/src/components/atoms/Changelog.tsx index 24e25e76..102a42f7 100644 --- a/src/components/atoms/Changelog.tsx +++ b/src/components/atoms/Changelog.tsx @@ -22,7 +22,6 @@ export function PureChangelog({ if (!repoMatch) return null const { object, url, owner } = repoMatch - if (!object) return null const changelogHtml = object && @@ -53,24 +52,22 @@ export function PureChangelog({ ) } -export default function Changelog({ repo }: { repo: string }) { - const queryGithub = graphql` - query GitHubReposInfo { - github { - viewer { - repositories(first: 100, privacy: PUBLIC, isFork: false) { - edges { - node { - name - url - owner { - login - } - object(expression: "master:CHANGELOG.md") { - id - ... on GitHub_Blob { - text - } +const queryGithub = graphql` + query GitHubReposInfo { + github { + viewer { + repositories(first: 100, privacy: PUBLIC, isFork: false) { + edges { + node { + name + url + owner { + login + } + object(expression: "master:CHANGELOG.md") { + id + ... on GitHub_Blob { + text } } } @@ -78,7 +75,10 @@ export default function Changelog({ repo }: { repo: string }) { } } } - ` + } +` + +export default function Changelog({ repo }: { repo: string }) { const data: GitHub = useStaticQuery(queryGithub) const repos: [{ node: GitHubRepo }] = data.github.viewer.repositories.edges return diff --git a/src/components/atoms/Container.test.tsx b/src/components/atoms/Container.test.tsx deleted file mode 100644 index 7d577082..00000000 --- a/src/components/atoms/Container.test.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import React from 'react' -// import { render } from '@testing-library/react' -import testRender from '../../../jest/testRender' - -import Container from './Container' - -describe('Container', () => { - testRender(Hello) -}) diff --git a/src/components/atoms/Copy.tsx b/src/components/atoms/Copy.tsx index 714f7e81..6efa05a8 100644 --- a/src/components/atoms/Copy.tsx +++ b/src/components/atoms/Copy.tsx @@ -14,7 +14,7 @@ export default function Copy({ text }: { text: string }) { onCopySuccess(e)} + onSuccess={(e: ClipboardJS.Event) => onCopySuccess(e)} className={styles.button} > diff --git a/src/components/atoms/Hamburger.test.tsx b/src/components/atoms/Hamburger.test.tsx deleted file mode 100644 index ad48e520..00000000 --- a/src/components/atoms/Hamburger.test.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import React from 'react' -// import { render } from '@testing-library/react' -import testRender from '../../../jest/testRender' - -import Hamburger from './Hamburger' - -describe('Hamburger', () => { - testRender( null} />) -}) diff --git a/src/components/atoms/Time.test.tsx b/src/components/atoms/Time.test.tsx deleted file mode 100644 index a23d0967..00000000 --- a/src/components/atoms/Time.test.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import React, { Suspense } from 'react' -import { render, waitForElement } from '@testing-library/react' - -import Time from './Time' - -describe('Time', () => { - test('renders lazy', async () => { - const { getByText } = render( - - - ) - const lazyElement = await waitForElement(() => getByText(/years ago/i)) - expect(lazyElement).toBeInTheDocument() - }) -}) diff --git a/src/components/molecules/Featured.tsx b/src/components/molecules/Featured.tsx index 577c2863..3eb93256 100644 --- a/src/components/molecules/Featured.tsx +++ b/src/components/molecules/Featured.tsx @@ -4,11 +4,23 @@ import { Image } from '../atoms/Image' import styles from './Featured.module.scss' import { Post } from '../../@types/Post' -function FeaturedPure({ - data -}: { - data: { allMarkdownRemark: { edges: [{ node: Post }] } } -}) { +const query = graphql` + query { + allMarkdownRemark( + filter: { frontmatter: { featured: { eq: true } } } + sort: { fields: [fields___date], order: DESC } + ) { + edges { + node { + ...PostTeaser + } + } + } + } +` + +export default function Featured() { + const data = useStaticQuery(query) return (
{data.allMarkdownRemark.edges.map(({ node }: { node: Post }) => { @@ -27,34 +39,3 @@ function FeaturedPure({
) } - -const query = graphql` - query { - allMarkdownRemark( - filter: { frontmatter: { featured: { eq: true } } } - sort: { fields: [fields___date], order: DESC } - ) { - edges { - node { - id - frontmatter { - title - image { - childImageSharp { - ...ImageFluidThumb - } - } - } - fields { - slug - } - } - } - } - } -` - -export default function Featured() { - const data = useStaticQuery(query) - return -} diff --git a/src/templates/Post/PostTeaser.module.scss b/src/components/molecules/PostTeaser.module.scss similarity index 100% rename from src/templates/Post/PostTeaser.module.scss rename to src/components/molecules/PostTeaser.module.scss diff --git a/src/templates/Post/PostTeaser.tsx b/src/components/molecules/PostTeaser.tsx similarity index 58% rename from src/templates/Post/PostTeaser.tsx rename to src/components/molecules/PostTeaser.tsx index 5cf0ee2d..3dee9f83 100644 --- a/src/templates/Post/PostTeaser.tsx +++ b/src/components/molecules/PostTeaser.tsx @@ -1,9 +1,32 @@ import React from 'react' -import { Link } from 'gatsby' -import { Image } from '../../components/atoms/Image' +import { Link, graphql } from 'gatsby' +import { Image } from '../atoms/Image' import styles from './PostTeaser.module.scss' import { Post } from '../../@types/Post' +export const postTeaserQuery = graphql` + fragment PostTeaser on MarkdownRemark { + id + fileAbsolutePath + frontmatter { + title + type + linkurl + tags + featured + image { + childImageSharp { + ...ImageFluidThumb + } + } + } + fields { + slug + date(formatString: "MMMM DD, YYYY") + } + } +` + export default function PostTeaser({ post, toggleSearch diff --git a/src/components/molecules/RelatedPosts.tsx b/src/components/molecules/RelatedPosts.tsx index c843a7ea..3e5d61f8 100644 --- a/src/components/molecules/RelatedPosts.tsx +++ b/src/components/molecules/RelatedPosts.tsx @@ -1,6 +1,6 @@ import React, { useState } from 'react' import { graphql, useStaticQuery } from 'gatsby' -import PostTeaser from '../../templates/Post/PostTeaser' +import PostTeaser from './PostTeaser' import styles from './RelatedPosts.module.scss' import { Post, Frontmatter } from '../../@types/Post' @@ -9,23 +9,7 @@ const query = graphql` allMarkdownRemark(sort: { order: DESC, fields: [fields___date] }) { edges { node { - id - fileAbsolutePath - frontmatter { - title - type - linkurl - tags - image { - childImageSharp { - ...ImageFluidThumb - } - } - } - fields { - slug - date(formatString: "MMMM DD, YYYY") - } + ...PostTeaser } } } diff --git a/src/components/molecules/Search/SearchResults.tsx b/src/components/molecules/Search/SearchResults.tsx index 0473f758..85717e78 100644 --- a/src/components/molecules/Search/SearchResults.tsx +++ b/src/components/molecules/Search/SearchResults.tsx @@ -2,7 +2,7 @@ import React from 'react' import ReactDOM from 'react-dom' import { graphql, useStaticQuery } from 'gatsby' import Container from '../../atoms/Container' -import PostTeaser from '../../../templates/Post/PostTeaser' +import PostTeaser from '../PostTeaser' import SearchResultsEmpty from './SearchResultsEmpty' import styles from './SearchResults.module.scss' import { Post } from '../../../@types/Post' @@ -16,18 +16,7 @@ const query = graphql` allMarkdownRemark { edges { node { - id - frontmatter { - title - image { - childImageSharp { - ...ImageFluidThumb - } - } - } - fields { - slug - } + ...PostTeaser } } } diff --git a/src/components/molecules/ThemeSwitch.tsx b/src/components/molecules/ThemeSwitch.tsx index f9998dcc..5a22aedb 100644 --- a/src/components/molecules/ThemeSwitch.tsx +++ b/src/components/molecules/ThemeSwitch.tsx @@ -29,23 +29,26 @@ const ThemeToggleInput = ({ /> ) +const HeadMarkup = ({ themeColor }: { themeColor: string }) => ( + + + + +) + export default function ThemeSwitch() { const darkMode = useDarkMode(false, { classNameDark: 'dark', classNameLight: 'light' }) - const themeColor = darkMode.value ? '#1d2224' : '#e7eef4' return ( <> - - - - +