Skip to content

Commit

Permalink
Merge pull request #32 from azachwill/devcommit35
Browse files Browse the repository at this point in the history
devcommit35
  • Loading branch information
awilliams1275 authored Aug 20, 2024
2 parents b023fcd + d44538e commit 5b0fbda
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
6 changes: 5 additions & 1 deletion _build/netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ path = "/py/"

[[edge_functions]]
function = "redirect_article"
path = "/*"
path = "/py/docs/*"

[[edge_functions]]
function = "redirect_article"
path = "/py/api/*"

[[redirects]]
from = "http://shiny.rstudio.com/*"
Expand Down
6 changes: 5 additions & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ path = "/py/"

[[edge_functions]]
function = "redirect_article"
path = "/*"
path = "/py/docs/*"

[[edge_functions]]
function = "redirect_article"
path = "/py/api/*"

[[redirects]]
from = "http://shiny.rstudio.com/*"
Expand Down
9 changes: 6 additions & 3 deletions netlify/edge-functions/redirect_article.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export default async (request, context) => {
const url = new URL(request.url);
// Check if the URL path starts with /docs and ends with a trailing slash
if ( (url.pathname.startsWith('/py/docs') || url.pathname.startsWith('/py/api') ) && url.pathname.endsWith('/') ) {
const pattern = /\/(core|express|testing)(\/?)$/;
const result = pattern.test(url);

// Check if the URL path is one of the index.html pages
if ( !result ) {
// Remove the trailing slash and add .html extension
const newPathname = url.pathname.slice(0, -1) + '.html';
const newUrl = `${url.origin}${newPathname}`;
Expand All @@ -18,6 +21,6 @@ export default async (request, context) => {
return context.next();
};
export const config = {
path: ['/*'],
path: ['/py/docs/*', "/py/api/*"],
};

0 comments on commit 5b0fbda

Please sign in to comment.