Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ny teknisk plattform: MDX, Algolia-søk, og innlogging #158

Merged
merged 67 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
67 commits
Select commit Hold shift click to select a range
83890e9
feat: adds mdx support
mikaelbr Jan 4, 2022
a842ed4
feat: changes to manual mdx pages
mikaelbr Jan 5, 2022
1e1a4fd
feat: use mdx as part of pages
mikaelbr Jan 7, 2022
12ec55c
removes unused code
mikaelbr Jan 7, 2022
eed29be
feat: adds auto injection of layout
mikaelbr Jan 12, 2022
16a0420
fix: comment on module
mikaelbr Jan 12, 2022
22b2f5c
feat: adds ability to do getServerSideProps for mdx files
mikaelbr Jan 12, 2022
89dab69
fix: remove log statement
mikaelbr Jan 12, 2022
4590b55
feat: adds ability to optionally login
mikaelbr Jan 12, 2022
0c63dac
feat: adds departure component
mikaelbr Jan 12, 2022
39da009
adds component for departure group
mikaelbr Jan 14, 2022
0359768
removes unused variable
mikaelbr Jan 31, 2022
1f0c476
init searchyness
mikaelbr Feb 3, 2022
cc4c644
refactor to indexer module
mikaelbr Feb 7, 2022
1b2926f
adds tree tools and attribute handling
mikaelbr Feb 7, 2022
36a12ea
adds indexing
mikaelbr Feb 7, 2022
0ee9fd8
feat: adds gray matter to index and clear on system for reindexing
mikaelbr Feb 8, 2022
107f8a9
feat: adds initial search
mikaelbr Feb 8, 2022
81efeef
fix: adds spacing to text indexing
mikaelbr Feb 8, 2022
4648455
fix: makes h3 linkable
mikaelbr Feb 8, 2022
e1def6f
feat: adds gh actions for indexing
mikaelbr Feb 8, 2022
3902f33
fix: better gh action\
mikaelbr Feb 8, 2022
421424f
temp pr
mikaelbr Feb 8, 2022
d8b4d07
temp pr
mikaelbr Feb 8, 2022
4ce50ab
fix only index on master
mikaelbr Feb 8, 2022
4c80172
feat: adds refinements to search
mikaelbr Feb 14, 2022
92c6cd1
fix: remove duplication search
mikaelbr Feb 25, 2022
87298c4
fix: sort by with types
mikaelbr Feb 25, 2022
1c18f5b
feat: adds support for departure on graymatter level
mikaelbr Mar 14, 2022
37aafcb
changes bergen to mdx
mikaelbr Mar 14, 2022
667c509
moves signin to sidebar
mikaelbr Mar 14, 2022
b1f4b02
updates search input design and login inputs
mikaelbr Mar 15, 2022
78169cb
adds department tabbar style and uu
mikaelbr Mar 15, 2022
5ed6221
adds initial design for search page
mikaelbr Mar 15, 2022
7373bbd
adds specific department faktura email
mikaelbr Mar 15, 2022
11bf75b
removes test department tabbar
mikaelbr Mar 15, 2022
50704e7
adds bergen to metadata
mikaelbr Mar 15, 2022
b103eb3
removes unused imports
mikaelbr Mar 15, 2022
f3e201b
Update search-index/index.mjs
mikaelbr Mar 17, 2022
0aee885
fix: issue with encoded uri
mikaelbr Mar 28, 2022
e962223
feat: adds anchor tags to h2/h3
mikaelbr Mar 28, 2022
2d42d63
chore: removes old redirects
mikaelbr Mar 28, 2022
b896dbd
refactor: removes unused code
mikaelbr Mar 28, 2022
55b0d0d
refactor: renames meta to frontmatter
mikaelbr Mar 28, 2022
8f2517a
refactor: updates to use variant common prettier config
mikaelbr Mar 28, 2022
960a6f9
fix: remove reset button from search
mikaelbr Mar 28, 2022
34ba9bc
Merge branch 'main' into v3
mikaelbr Oct 15, 2022
f55e181
fix: linkable for frontpage
mikaelbr Oct 15, 2022
4917d5e
chore: updates all dependencies
mikaelbr Oct 15, 2022
dfe7095
chore: gitignores next-env.d.ts
mikaelbr Oct 15, 2022
4d7274e
fix: login for new azure impl
mikaelbr Oct 15, 2022
809bb2c
docs: adds docs on env vars
mikaelbr Oct 15, 2022
16795fd
fix: typing issues
mikaelbr Oct 15, 2022
b89b040
fix: indexing from ast
mikaelbr Oct 15, 2022
9d8232a
fix: upgrades instasearch to ssr
mikaelbr Oct 16, 2022
3c2b324
fix: tweaks style search site
mikaelbr Oct 16, 2022
2abb215
fix: searchbox
mikaelbr Oct 16, 2022
7da599b
feat: adds search box to frontpage
mikaelbr Oct 16, 2022
bb67a07
feat: adds production-build script
mikaelbr Oct 16, 2022
b52a60b
ci: adds production-build with indexing
mikaelbr Oct 16, 2022
852c2cc
fix: sidebar navigation mobile
mikaelbr Oct 17, 2022
190a962
fix: adds config for font loading
mikaelbr Oct 17, 2022
0467f0d
fix: adds fallback department getter
mikaelbr Oct 17, 2022
72c0383
fix: better fallback when missing department
mikaelbr Oct 17, 2022
51af23d
fix: better phone department selector
mikaelbr Oct 17, 2022
2240bb0
fix: padding refinement list
mikaelbr Oct 18, 2022
6ebf7fb
refactor: reduce nested if clauses
mikaelbr Oct 18, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 1,17 @@
# Get from Azure AD registered App settings (only required if you want to test login)
AZURE_AD_CLIENT_ID=
AZURE_AD_CLIENT_SECRET=
AZURE_AD_TENANT_ID=

# Random string for cookie secrets
JWT_COOKIE_SECRET=


# Settings for indexing (not required unless you're testing indexing)
BASE_URL=https://handbook.variant.no
ALGOLIA_APP_ID=
ALGOLIA_API_KEY=

# Used for searching by client. Public keys
NEXT_PUBLIC_ALGOLIA_APP_ID=WZBDX5TTC9
NEXT_PUBLIC_ALGOLIA_READ_KEY=184c48e3d13eb260eab5a8e980234778
6 changes: 3 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 4,13 @@ module.exports = {
es2020: true,
node: true,
},
extends: ["plugin:react-hooks/recommended"],
parser: "@typescript-eslint/parser",
extends: ['plugin:react-hooks/recommended'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 11,
sourceType: "module",
sourceType: 'module',
},
};
60 changes: 30 additions & 30 deletions .github/spellchecker.yml
Original file line number Diff line number Diff line change
@@ -1,33 1,33 @@
language: "nb_NO"
dictionary_folder: "no"
main_comment: "Jeg fant en eller flere mulige skrivefeil 😇"
language: 'nb_NO'
dictionary_folder: 'no'
main_comment: 'Jeg fant en eller flere mulige skrivefeil 😇'
ignored_words:
[
"Mikael",
"variant",
"ammefri",
"digs",
"jante",
"gadget",
"DIY",
"Gjensidige",
"MacBook",
"Mac",
"helpdesk",
"Open",
"Source",
"GitHub",
"app",
"apps",
"startup",
"blog",
"Trello",
"Tekna",
"Harvest",
"JetBrains",
"Slack",
"podcast",
"innedag",
"Angells",
"wifi"
'Mikael',
'variant',
'ammefri',
'digs',
'jante',
'gadget',
'DIY',
'Gjensidige',
'MacBook',
'Mac',
'helpdesk',
'Open',
'Source',
'GitHub',
'app',
'apps',
'startup',
'blog',
'Trello',
'Tekna',
'Harvest',
'JetBrains',
'Slack',
'podcast',
'innedag',
'Angells',
'wifi',
]
21 changes: 21 additions & 0 deletions .github/workflows/indexer.yml
Original file line number Diff line number Diff line change
@@ -0,0 1,21 @@
name: CI
on:
push:
branches:
- master
jobs:
build:
name: Run search index
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16'
cache: 'yarn'
- run: yarn install
- run: yarn search-index
env:
BASE_URL: ${{ secrets.BASE_URL }}
ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
7 changes: 3 additions & 4 deletions .github/workflows/label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 3,9 @@ on: [pull_request]

jobs:
label:

runs-on: ubuntu-latest

steps:
- uses: actions/labeler@v2
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
- uses: actions/labeler@v2
with:
repo-token: '${{ secrets.GITHUB_TOKEN }}'
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 106,8 @@ dist
.DS_Store

# IntelliJ
.idea/
.idea/

next-env.d.ts

.env.local
2 changes: 0 additions & 2 deletions .prettierignore

This file was deleted.

3 changes: 0 additions & 3 deletions .prettierrc

This file was deleted.

34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 10,40 @@ Edit text by changing files in [content](./content).

`yarn dev` to run development server

## Configuration

The handbook should run locally without any variables, but there are some features requiring them.
Without AZURE AD configuration, login won't work. Without ALGOLIA configuration indexing won't work.
These are how ever optional features and the handbook will work fine without them.

See [`.env.example`](./.env.example) for required environment variables:

```
# Get from Azure AD registered App settings (only required if you want to test login)
AZURE_AD_CLIENT_ID=
AZURE_AD_CLIENT_SECRET=
AZURE_AD_TENANT_ID=

# Random string for cookie secrets
JWT_COOKIE_SECRET=


# Settings for indexing (not required unless you're testing indexing)
BASE_URL=https://handbook.variant.no
ALGOLIA_APP_ID=
ALGOLIA_API_KEY=

# Used for searching by client. Public keys
NEXT_PUBLIC_ALGOLIA_APP_ID=WZBDX5TTC9
NEXT_PUBLIC_ALGOLIA_READ_KEY=184c48e3d13eb260eab5a8e980234778
```

If you have access to Vercel you can generate secrets by doing:

```
vercel env pull
```

### Architecture and design decisions

Organizing is done through module folders where all relevant files are located. This is to easer be able to remove/delete code and complete sets of code. However, there are some assets (e.g. manifest files and some images) which are more practical as public files (inside `public/`). These will be available as static files hosted on the root path.
Expand Down
12 changes: 12 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 1,12 @@
#!/bin/bash

if [[ "$VERCEL_ENV" == "production" ]]
then
echo "Production build. Indexing..."
node search-index/index.mjs
next build
else
echo "Environment $VERCEL_ENV. Not indexing..."
next build
fi
date
4 changes: 0 additions & 4 deletions content/avdelinger/index.md

This file was deleted.

21 changes: 21 additions & 0 deletions mdx-plugins/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 1,21 @@
import { remarkMdxToc } from 'remark-mdx-toc';
import remarkFrontmatter from 'remark-frontmatter';
import remarkMdxFrontmatter from 'remark-mdx-frontmatter';
import { remark } from 'remark';
import remarkMdx from 'remark-mdx';

export const plugins = [
remarkFrontmatter,
[remarkMdxFrontmatter, { name: 'frontmatter' }],
remarkMdxToc,
];

export function vfileToAst(vfile) {
const data = remark()
.use(remarkFrontmatter)
.use([remarkMdxFrontmatter, { name: 'frontmatter' }])
.use(remarkMdxToc)
.use(remarkMdx)
.parse(vfile);
return data;
}
48 changes: 48 additions & 0 deletions mdx-plugins/load-layout.js
Original file line number Diff line number Diff line change
@@ -0,0 1,48 @@
const fm = require('gray-matter');
const path = require('path');
const fg = require('fast-glob');

// Makes mdx in next.js suck less by injecting necessary exports so that
// the docs are still readable on github.
//
// Layout component for a .mdx or .md page can be specfied in the frontmatter.
// If no layout is wanted tag with `layout: none` in frontmatter. Default layout
// is "handbook". Add new layout to src/layouts with same signature.
//
// All metadata can be written in yaml front matter. It will be passed to the
// layout component as `frontmatter` prop.
//
// (Shamelessly stolen from React docs who has shamelessly stolen from Expo.io docs)
// @see https://github.com/reactjs/reactjs.org/blob/main/beta/plugins/md-layout-loader.js
// @see https://github.com/expo/expo/blob/master/docs/common/md-loader.js

module.exports = async function (src) {
const callback = this.async();
const { data } = fm(src);
const layoutFolders = await fg(path.join(__dirname, '../src/layouts/*'), {
onlyDirectories: true,
});
const availableLayouts = layoutFolders
.map((r) => path.basename(r))
.concat('none');

const layout = availableLayouts.includes(data.layout)
? data.layout
: 'handbook';

if (layout === 'none') {
return callback(null, src);
}

const code =
src
`
import Layout, { getServerSideProps } from 'src/layouts/${layout}';

export default (props) => <Layout frontmatter={frontmatter} toc={toc} {...props} />;

export { getServerSideProps };
`;

return callback(null, code);
};
4 changes: 0 additions & 4 deletions next-env.d.ts

This file was deleted.

47 changes: 0 additions & 47 deletions next.config.js

This file was deleted.

Loading