├── README.md ├── .gitignore ├── .eslintrc.json ├── lambdas └── _cdn │ ├── origin-response.ts │ ├── origin-request.ts │ └── viewer-request.ts ├── tsconfig.json ├── LICENSE ├── .github └── workflows │ └── main_lambdas.yaml ├── webpack.lambda.config.js ├── aws.tf └── package.json /README.md: -------------------------------------------------------------------------------- 1 | # ARCHIVED 2 | 3 | https://roamjs.com now redirects to our GitHub organization for all RoamJS extensions: https://github.com/RoamJS 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | terraform.exe 3 | .terraform/ 4 | build/ 5 | dist/ 6 | out/ 7 | .next/ 8 | .env 9 | .env.local 10 | test.js 11 | /app/tailwind.css 12 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "plugins": ["@typescript-eslint"], 5 | "extends": [ 6 | "eslint:recommended", 7 | "plugin:@typescript-eslint/eslint-recommended", 8 | "plugin:@typescript-eslint/recommended" 9 | ], 10 | "rules": { 11 | "no-control-regex": 0, 12 | "@typescript-eslint/no-unused-vars": [ 13 | "error", 14 | { "argsIgnorePattern": "_+" } 15 | ] 16 | }, 17 | "ignorePatterns": ["**/dist/*", "scripts/"] 18 | } 19 | -------------------------------------------------------------------------------- /lambdas/_cdn/origin-response.ts: -------------------------------------------------------------------------------- 1 | import { CloudFrontResponseHandler } from "aws-lambda"; 2 | 3 | export const handler: CloudFrontResponseHandler = (event, _, callback) => { 4 | const { request, response } = event.Records[0].cf; 5 | if (/\.js$/.test(request.uri)) { 6 | response.headers["Cache-Control"] = [{ value: "no-store" }]; 7 | } else { 8 | response.headers["Cache-Control"] = [{ value: "no-cache" }]; 9 | } 10 | if (/\/download\/extension\.js$/i.test(request.uri)) { 11 | response.headers["Content-Disposition"] = [ 12 | { value: `attachment; filename="extension.js"` }, 13 | ]; 14 | } 15 | return callback(null, response); 16 | }; 17 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "./build/", 4 | "noImplicitAny": true, 5 | "allowSyntheticDefaultImports": true, 6 | "moduleResolution": "node", 7 | "module": "esnext", 8 | "target": "es2019", 9 | "esModuleInterop": true, 10 | "allowJs": true, 11 | "jsx": "preserve", 12 | "lib": ["dom", "dom.iterable", "esnext"], 13 | "skipLibCheck": true, 14 | "strict": false, 15 | "forceConsistentCasingInFileNames": true, 16 | "noEmit": true, 17 | "resolveJsonModule": true, 18 | "isolatedModules": true, 19 | "importHelpers": true 20 | }, 21 | "include": ["lambdas"], 22 | "exclude": ["node_modules"] 23 | } 24 | -------------------------------------------------------------------------------- /lambdas/_cdn/origin-request.ts: -------------------------------------------------------------------------------- 1 | import { CloudFrontRequestHandler } from "aws-lambda"; 2 | 3 | const movedUris = [ 4 | "developer", 5 | "github", 6 | "google-calendar", 7 | "static-site", 8 | "query-builder", 9 | "todo-trigger", 10 | "twitter", 11 | ].map((e) => `/${e}.js`); 12 | 13 | // In the future, move this to the roamjs static site generator 14 | const REDIRECTS: Record = { 15 | "/multiplayer/main.js": "/samepage/main.js", 16 | // "/roam42/main.js": "/roam42/main.js", 17 | }; 18 | 19 | export const handler: CloudFrontRequestHandler = (event, _, callback) => { 20 | const request = event.Records[0].cf.request; 21 | const olduri = request.uri; 22 | if (movedUris.includes(olduri)) { 23 | request.uri = olduri.replace(/\.js$/, "/main.js"); 24 | } else if (olduri.endsWith("/") && olduri.length > 1) { 25 | request.uri = olduri.replace(/\/$/, ""); 26 | } else if (REDIRECTS[olduri]) { 27 | request.uri = REDIRECTS[olduri]; 28 | } else { 29 | return callback(null, request); 30 | } 31 | console.log("Mapped", olduri, "to", request.uri); 32 | return callback(null, request); 33 | }; 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 David Vargas 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.github/workflows/main_lambdas.yaml: -------------------------------------------------------------------------------- 1 | name: Push Lambdas to Main 2 | on: 3 | workflow_dispatch: 4 | push: 5 | branches: main 6 | paths: 7 | - "lambdas/**" 8 | - "webpack.lambda.config.js" 9 | - "tsconfig.json" 10 | - ".github/workflows/main_lambdas.yaml" 11 | 12 | env: 13 | AWS_ACCESS_KEY_ID: ${{ secrets.DEPLOY_AWS_ACCESS_KEY }} 14 | AWS_SECRET_ACCESS_KEY: ${{ secrets.DEPLOY_AWS_ACCESS_SECRET }} 15 | AWS_DEFAULT_REGION: us-east-1 16 | 17 | jobs: 18 | deploy: 19 | runs-on: ubuntu-20.04 20 | steps: 21 | - uses: actions/checkout@v3 22 | - name: install 23 | run: npm install --force 24 | - name: Build 25 | run: npm run build:lambdas 26 | - name: Upload 27 | run: | 28 | for filename in out/*.js; do 29 | LAMBDA=$(basename "$filename" .js) 30 | zip -jq $LAMBDA.zip ./out/$LAMBDA.js 31 | MODIFIED=$(aws lambda update-function-code --function-name "roamjs-com_${LAMBDA}" --publish --zip-file "fileb://${LAMBDA}.zip" --query "LastModified" --output text) 32 | rm $LAMBDA.zip 33 | echo "Function $LAMBDA successfully updated at $MODIFIED" 34 | done 35 | -------------------------------------------------------------------------------- /webpack.lambda.config.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"); 2 | const path = require("path"); 3 | 4 | const buildEntry = (dir) => { 5 | const srcDir = dir === "lambdas" ? `./lambdas/_cdn/` : `./src/${dir}/`; 6 | const extensions = fs.readdirSync(srcDir); 7 | const entry = Object.fromEntries( 8 | extensions.map((e) => [e.substring(0, e.length - 3), `${srcDir}${e}`]) 9 | ); 10 | return entry; 11 | }; 12 | 13 | module.exports = (env) => ({ 14 | target: "node", 15 | entry: buildEntry(env.dir || "api"), 16 | resolve: { 17 | extensions: [".ts", ".js"], 18 | }, 19 | mode: "production", 20 | output: { 21 | libraryTarget: "commonjs2", 22 | path: path.join(__dirname, "out"), 23 | filename: "[name].js", 24 | strictModuleExceptionHandling: true, 25 | }, 26 | externals: ["aws-sdk"], 27 | module: { 28 | rules: [ 29 | { 30 | test: /\.ts$/, 31 | use: [ 32 | { 33 | loader: "ts-loader", 34 | options: { 35 | compilerOptions: { 36 | noEmit: false, 37 | }, 38 | }, 39 | }, 40 | ], 41 | exclude: /node_modules/, 42 | }, 43 | ], 44 | }, 45 | }); 46 | -------------------------------------------------------------------------------- /aws.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "remote" { 3 | hostname = "app.terraform.io" 4 | organization = "VargasArts" 5 | workspaces { 6 | name = "roam-js-extensions" 7 | } 8 | } 9 | 10 | required_providers { 11 | github = { 12 | source = "integrations/github" 13 | } 14 | } 15 | } 16 | 17 | variable "secret" { 18 | type = string 19 | } 20 | 21 | provider "aws" { 22 | region = "us-east-1" 23 | } 24 | 25 | module "aws_static_site" { 26 | source = "dvargas92495/static-site/aws" 27 | version = "2.3.6" 28 | 29 | domain = "roamjs.com" 30 | redirects = ["roam.davidvargas.me"] 31 | secret = var.secret 32 | allowed_origins = ["https://roamresearch.com"] 33 | tags = { 34 | Application = "Roam JS Extensions" 35 | } 36 | 37 | providers = { 38 | aws.us-east-1 = aws 39 | } 40 | } 41 | 42 | module "aws_email" { 43 | source = "dvargas92495/email/aws" 44 | version = "2.0.3" 45 | 46 | domain = "roamjs.com" 47 | zone_id = module.aws_static_site.route53_zone_id 48 | } 49 | 50 | resource "aws_route53_record" "google-verifu" { 51 | zone_id = module.aws_static_site.route53_zone_id 52 | name = "roamjs.com" 53 | type = "TXT" 54 | ttl = "300" 55 | records = ["google-site-verification=A9q11tN2qoTRaIdwMmlNqvbjgX4UQOj1okRat6CHtyE"] 56 | } 57 | 58 | resource "aws_dynamodb_table" "auth" { 59 | name = "RoamJSAuth" 60 | billing_mode = "PAY_PER_REQUEST" 61 | hash_key = "id" 62 | 63 | attribute { 64 | name = "id" 65 | type = "S" 66 | } 67 | 68 | tags = { 69 | Application = "Roam JS Extensions" 70 | } 71 | } 72 | 73 | resource "aws_api_gateway_rest_api" "lambda_api" { 74 | name = "roamjs-extensions" 75 | 76 | endpoint_configuration { 77 | types = ["REGIONAL"] 78 | } 79 | 80 | binary_media_types = [ 81 | "multipart/form-data", 82 | "application/octet-stream" 83 | ] 84 | 85 | tags = { 86 | Application = "Roam JS Extensions" 87 | } 88 | } 89 | 90 | resource "aws_acm_certificate" "api" { 91 | domain_name = "lambda.roamjs.com" 92 | validation_method = "DNS" 93 | 94 | tags = { 95 | Application = "Roam JS Extensions" 96 | } 97 | 98 | lifecycle { 99 | create_before_destroy = true 100 | } 101 | } 102 | 103 | resource "aws_route53_record" "api_cert" { 104 | name = tolist(aws_acm_certificate.api.domain_validation_options)[0].resource_record_name 105 | type = tolist(aws_acm_certificate.api.domain_validation_options)[0].resource_record_type 106 | zone_id = module.aws_static_site.route53_zone_id 107 | records = [tolist(aws_acm_certificate.api.domain_validation_options)[0].resource_record_value] 108 | ttl = 60 109 | } 110 | 111 | resource "aws_acm_certificate_validation" "api" { 112 | certificate_arn = aws_acm_certificate.api.arn 113 | validation_record_fqdns = [aws_route53_record.api_cert.fqdn] 114 | } 115 | 116 | resource "aws_api_gateway_domain_name" "api" { 117 | certificate_arn = aws_acm_certificate_validation.api.certificate_arn 118 | domain_name = "lambda.roamjs.com" 119 | } 120 | 121 | resource "aws_route53_record" "api" { 122 | name = aws_api_gateway_domain_name.api.domain_name 123 | type = "A" 124 | zone_id = module.aws_static_site.route53_zone_id 125 | 126 | alias { 127 | evaluate_target_health = true 128 | name = aws_api_gateway_domain_name.api.cloudfront_domain_name 129 | zone_id = aws_api_gateway_domain_name.api.cloudfront_zone_id 130 | } 131 | } 132 | 133 | resource "aws_api_gateway_deployment" "production" { 134 | rest_api_id = aws_api_gateway_rest_api.lambda_api.id 135 | stage_name = "production" 136 | } 137 | 138 | resource "aws_api_gateway_base_path_mapping" "api" { 139 | api_id = aws_api_gateway_rest_api.lambda_api.id 140 | stage_name = aws_api_gateway_deployment.production.stage_name 141 | domain_name = aws_api_gateway_domain_name.api.domain_name 142 | } 143 | 144 | provider "github" { 145 | owner = "dvargas92495" 146 | } 147 | 148 | resource "github_actions_secret" "deploy_aws_access_key" { 149 | repository = "roamjs-com" 150 | secret_name = "DEPLOY_AWS_ACCESS_KEY" 151 | plaintext_value = module.aws_static_site.deploy-id 152 | } 153 | 154 | resource "github_actions_secret" "deploy_aws_access_secret" { 155 | repository = "roamjs-com" 156 | secret_name = "DEPLOY_AWS_ACCESS_SECRET" 157 | plaintext_value = module.aws_static_site.deploy-secret 158 | } 159 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "roamjs-com", 3 | "version": "1.0.1", 4 | "description": "Various Roam Javascript extensions deployed to roamjs.com", 5 | "main": "index.js", 6 | "scripts": { 7 | "build:lambdas": "webpack --config ./webpack.lambda.config.js --env dir=lambdas" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/dvargas92495/roamjs-com.git" 12 | }, 13 | "keywords": [ 14 | "Roam" 15 | ], 16 | "author": "dvargas92495", 17 | "license": "MIT", 18 | "bugs": { 19 | "url": "https://github.com/dvargas92495/roamjs-com/issues" 20 | }, 21 | "homepage": "https://github.com/dvargas92495/roamjs-com#readme", 22 | "devDependencies": { 23 | "@babel/core": "^7.12.3", 24 | "@babel/preset-env": "^7.12.1", 25 | "@babel/preset-react": "^7.12.1", 26 | "@types/aws-lambda": "^8.10.61", 27 | "@types/busboy": "^0.2.3", 28 | "@types/charset": "^1.0.2", 29 | "@types/crypto-js": "^4.0.2", 30 | "@types/downloadjs": "^1.4.2", 31 | "@types/draft-js": "^0.10.44", 32 | "@types/jest": "^26.0.24", 33 | "@types/jsdom": "^16.2.5", 34 | "@types/leaflet": "^1.5.19", 35 | "@types/mdx-js__react": "^1.5.3", 36 | "@types/mime-types": "^2.1.0", 37 | "@types/node-emoji": "^1.8.1", 38 | "@types/randomstring": "^1.1.6", 39 | "@types/react-dom": "^16.9.8", 40 | "@types/turndown": "^5.0.0", 41 | "@types/twitter-text": "^3.1.0", 42 | "@typescript-eslint/eslint-plugin": "^4.10.0", 43 | "@typescript-eslint/parser": "^4.10.0", 44 | "@vercel/ncc": "^0.26.2", 45 | "@webpack-cli/serve": "^1.7.0", 46 | "autoprefixer": "^10.4.7", 47 | "babel-loader": "^8.1.0", 48 | "babel-preset-env": "^1.7.0", 49 | "concurrently": "^6.4.0", 50 | "copy-webpack-plugin": "^7.0.0", 51 | "cross-env": "^7.0.3", 52 | "css-loader": "^5.0.1", 53 | "cypress": "^9.5.3", 54 | "dotenv": "^8.2.0", 55 | "eslint": "^7.32.0", 56 | "file-loader": "^6.2.0", 57 | "http-server": "^0.12.3", 58 | "jest": "^27.0.6", 59 | "localhost-lambdas": "^0.6.3", 60 | "next-react-svg": "^1.1.2", 61 | "node-polyfill-webpack-plugin": "^2.0.0", 62 | "open": "^8.0.6", 63 | "postcss": "^8.4.14", 64 | "react-hot-loader": "^4.13.0", 65 | "source-map-loader": "^1.1.3", 66 | "style-loader": "^2.0.0", 67 | "svg-react-loader": "^0.4.6", 68 | "tailwindcss": "^3.1.4", 69 | "ts-loader": "^9.3.1", 70 | "typescript": "^4.5.2", 71 | "url-loader": "^4.1.1", 72 | "webpack": "^5.73.0", 73 | "webpack-bundle-analyzer": "^4.5.0", 74 | "webpack-cli": "^4.10.0", 75 | "webpack-dev-server": "^4.9.2" 76 | }, 77 | "dependencies": { 78 | "@blueprintjs/core": "^3.41.0", 79 | "@blueprintjs/datetime": "^3.20.5", 80 | "@blueprintjs/select": "^3.14.3", 81 | "@giphy/js-fetch-api": "^2.0.1", 82 | "@mapbox/rehype-prism": "^0.5.0", 83 | "@mdx-js/loader": "^1.6.19", 84 | "@mozilla/readability": "^0.3.0", 85 | "@sentry/browser": "^5.29.2", 86 | "@sentry/tracing": "^5.29.2", 87 | "@stripe/stripe-js": "^1.11.0", 88 | "@types/mozilla-readability": "^0.2.0", 89 | "aws-sdk": "^2.824.0", 90 | "axios": "^0.21.4", 91 | "babel-plugin-import-glob-array": "^0.2.0", 92 | "busboy": "^0.3.1", 93 | "canvg": "^3.0.7", 94 | "charset": "^1.0.1", 95 | "chrono-node": "^2.2.6", 96 | "crypto-js": "^4.1.1", 97 | "date-fns": "^2.16.1", 98 | "diahook": "^0.11.5", 99 | "draft-js": "^0.11.7", 100 | "dropbox": "^9.6.0", 101 | "form-data": "^4.0.0", 102 | "gray-matter": "^4.0.3", 103 | "iconv-lite": "^0.6.2", 104 | "iframe-resizer": "^4.2.11", 105 | "iframe-resizer-react": "^1.0.4", 106 | "imagemin-mozjpeg": "^9.0.0", 107 | "imagemin-optipng": "^8.0.0", 108 | "leaflet": "^1.7.1", 109 | "markdown-to-jsx": "^7.1.0", 110 | "mime-types": "^2.1.30", 111 | "mobile-device-detect": "^0.4.3", 112 | "nanoid": "^4.0.1", 113 | "next-mdx-enhanced": "^5.0.0", 114 | "next-mdx-remote": "^3.0.2-alpha.0", 115 | "next-optimized-images": "^2.6.2", 116 | "node-emoji": "^1.10.0", 117 | "oauth-1.0a": "^2.2.6", 118 | "randomstring": "^1.1.5", 119 | "react": "^17.0.2", 120 | "react-dom": "^17.0.2", 121 | "react-leaflet": "^3.0.2", 122 | "react-manage-users": "^0.3.3", 123 | "react-syntax-highlighter": "^15.2.1", 124 | "react-tweet-embed": "^1.2.2", 125 | "react-youtube": "^7.13.1", 126 | "remark-autolink-headings": "^6.0.1", 127 | "remark-code-titles": "^0.1.1", 128 | "remark-slug": "^6.0.0", 129 | "remark-unwrap-images": "^2.0.0", 130 | "reveal.js": "^4.3.0", 131 | "stripe": "^8.187.0", 132 | "turndown": "^7.0.0", 133 | "twitter-text": "^3.1.0", 134 | "universal-cookie": "^4.0.4", 135 | "uuid": "^8.3.2" 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /lambdas/_cdn/viewer-request.ts: -------------------------------------------------------------------------------- 1 | import { CloudFrontRequestHandler } from "aws-lambda"; 2 | 3 | // In the future, move this to the roamjs static site generator 4 | const LEGACY_REDIRECTS: Record = { 5 | "/extensions/query-tools": "/extensions/query-builder", 6 | "/extensions/roam42": "/extensions/workbench", 7 | "/extensions/roam42/workbench": "/extensions/workbench/command_palette_plus", 8 | "/extensions/roam42/live_preview": "/extensions/workbench/live_preview", 9 | "/extensions/roam42/daily_note_popup": 10 | "/extensions/workbench/daily_note_popup", 11 | "/extensions/roam42/jump_navigation": "/extensions/workbench/hot_keys", 12 | "/extensions/roam42/deep_nav": "/extensions/workbench/deep_nav", 13 | "/extensions/roam42/privacy_mode": "/extensions/workbench/privacy_mode", 14 | "/extensions/roam42/dictionary": "/extensions/workbench/dictionary", 15 | "/extensions/roam42/strikeout-text-shortcut": "/extensions/workbench", 16 | "/extensions/roam42/update_log": "/extensions/workbench", 17 | "/extensions/roam42/date_nlp": "/extensions/workbench/daily_note_popup", 18 | "/extensions/charts": "/extensions/query-builder", 19 | "/extensions/timeline": "/extensions/query-builder", 20 | "/extensions/attr-tables": "/extensions/query-builder", 21 | "/extensions/google-calendar": "/extensions/google", 22 | "/extensions/google-drive": "/extensions/google", 23 | "/extensions/github": "/extensions/developer", 24 | "/extensions/repl": "/extensions/developer", 25 | "/extensions/alert": "/extensions/workbench/alert", 26 | "/extensions/mouseless": "/extensions/workbench/hot_keys", 27 | "/extensions/multi-select": 28 | "https://roamresearch.com/#/app/help/page/rQOT9lVIP", 29 | "/extensions/pull-references": "/extensions/workbench/command_palette_plus", 30 | "/extensions/calculate": "/extensions/query-builder", 31 | "/extensions/article": "/extensions/workbench/article", 32 | "/extensions/sort-references": "/extensions/query-builder", 33 | "/extensions/emojis": "/extensions/workbench", 34 | "/extensions/todont": "/extensions/todo-trigger", 35 | "/extensions/weekly-notes": "/extensions/workbench/weekly-notes", 36 | "/extensions/sidebar": "https://github.com/mlava/workspaces", 37 | "/extensions/iframely": "/extensions", 38 | "/extensions/image-tagging": "/extensions/workbench/image_ocr", 39 | "/extensions/mobile-todos": 40 | "https://roamresearch.com/#/app/help/page/KnvM2AMyC", 41 | "/extensions/mindmap": "/extensions/workbench/mindmap", 42 | "/extensions/postman": "/extensions/developer", 43 | "/extensions/serendipity": 44 | "/extensions/smartblocks/command_reference#Md9KfcSaH", 45 | "/extensions/sparql": "/extensions/developer", 46 | "/extensions/tally": "/extensions/workbench/tally", 47 | "/extensions/workbench/multi_select": 48 | "https://roamresearch.com/#/app/help/page/rQOT9lVIP", 49 | "/extensions/tag-cycle": "/extensions/workbench/tag_cycle", 50 | "/extensions/wysiwyg-mode": "/extensions", 51 | "/extensions/wiki-data": "https://github.com/mlava/wikipedia", 52 | "/extensions/filter-embeds": "/extensions", 53 | "/extensions/video": "/extensions", 54 | "/extensions/marketplace": "/extensions", 55 | "/contribute": "/extensions", 56 | "/subscribe": "https://roamjs.com", 57 | "/queue": "https://roamjs.com", 58 | "/projects": "https://roamjs.com", 59 | "/extensions/roam42/smartblocks": "/extensions/smartblocks", 60 | "/extensions/roam42/smartblocks:_trigger": 61 | "/extensions/smartblocks/trigger_your_workflow", 62 | "/extensions/roam42/smartblocks:_understand": 63 | "/extensions/smartblocks/understanding_commands", 64 | "/extensions/roam42/smartblocks:_using_predefined_workflows": 65 | "/extensions/smartblocks/using_pre-defined_workflows", 66 | "/extensions/roam42/smartblocks:_make_your_own_workflows": 67 | "/extensions/smartblocks/make_your_own_workflows", 68 | "/extensions/roam42/smartblocks:_command_reference_by_category": 69 | "/extensions/smartblocks/command_reference", 70 | "/extensions/roam42/smartblocks:_command_processing_order": 71 | "/extensions/smartblocks/command_reference", 72 | "/extensions/roam42/smartblocks:_alternative_methods": 73 | "/extensions/smartblocks/alternative_methods", 74 | "/extensions/roam42/smartblocks:_customization": "/extensions/smartblocks", 75 | "/extensions/roam42/smartblocks:_developer_docs": 76 | "/extensions/smartblocks/developer_docs", 77 | "/extensions": "/", 78 | "/privacy-policy": "https://samepage.network/privacy-policy", 79 | "/terms-of-use": "https://samepage.network/terms-of-use", 80 | }; 81 | 82 | export const handler: CloudFrontRequestHandler = (event, _, callback) => { 83 | const request = event.Records[0].cf.request; 84 | const olduri = request.uri; 85 | if ( 86 | olduri === "/oauth" || 87 | olduri.startsWith("/images") || 88 | olduri.endsWith(".js") 89 | ) { 90 | return callback(null, request); 91 | } 92 | const redirect = (newUri: string) => { 93 | const response = { 94 | status: "301", 95 | statusDescription: "Moved Permanently", 96 | headers: { 97 | location: [ 98 | { 99 | key: "Location", 100 | value: newUri.startsWith("https") 101 | ? newUri 102 | : `https://roamjs.com${newUri}`, 103 | }, 104 | ], 105 | }, 106 | }; 107 | return callback(null, response); 108 | }; 109 | const legacyUri = /^\/docs(\/extensions)?/.test(olduri) 110 | ? olduri.replace(/^\/docs(\/extensions)?/, "/extensions") 111 | : /^\/services\/social(\/)?/.test(olduri) 112 | ? "/extensions/twitter" 113 | : /^\/services(.*)$/.test(olduri) 114 | ? olduri.replace(/^\/services(.*)$/, "/extensions$1") 115 | : LEGACY_REDIRECTS[olduri] && olduri; 116 | 117 | const extensionPath = 118 | /^\/extensions\/(.*)(?:\/.*)?$/.exec(legacyUri)?.[1] || ""; 119 | const newUri = extensionPath 120 | ? `https://github.com/RoamJS/${extensionPath}` 121 | : "https://github.com/RoamJS"; 122 | return redirect(newUri); 123 | }; 124 | --------------------------------------------------------------------------------