Skip to content

Commit

Permalink
Sander/docs hotfix (scullyio#647)
Browse files Browse the repository at this point in the history
* fix(scully): fix config handling when option `--404=''`

* docs(docsWeb): hotfix for not building routes

* fix(scully): read wrong folder for source files
  • Loading branch information
SanderElias authored Jun 23, 2020
1 parent e2745cd commit 6ffa567
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import { Component, Input } from '@angular/core';
@Component({
selector: 'app-left-menu',
templateUrl: './left-menu.component.html',
styleUrls: ['./left-menu.component.css']
styleUrls: ['./left-menu.component.css'],
})
export class LeftMenuComponent {
@Input() set list(_list: any[]) {
this.fullList.push(..._list);
if (Array.isArray(_list)) {
this.fullList.push(..._list);
}

this.changeLang();
}
@Input() first = true;
Expand All @@ -19,8 +22,8 @@ export class LeftMenuComponent {
changeLang() {
this.showList = [];
if (this.fullList) {
this.fullList.forEach(post => {
if (post.lang === this.lang) {
this.fullList.forEach((post) => {
if (post && post.lang === this.lang) {
this.showList.push(post);
}
});
Expand Down
4 changes: 2 additions & 2 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const config: ScullyConfig = {
projectRoot: './src',
projectName: '<projectName>',
outDir: './dist/static',
routes: {}
routes: {},
};
```

Expand Down Expand Up @@ -97,7 +97,7 @@ This message indicates that Scully has skept any unconfigured routes. Read more

Once the app is built with Scully, see the output and test how it runs as a statically generated webpage.

To see the pre-rendered site, open the `/dist/static` folder where you can find one `index.html` for every route in your app. Hence, if the application has 1000 routes, there should be 1000 `index.html` files in the `dist/static` folder.
To see the pre-rendered site, open the `/dist/static` folder where you can find one `index.html` for every route in your app. Hence, if the application has 1000 routes, there should be 1000 `index.html` files in the `dist/static` folder.
These `index.html` files are jamstack-packed with HTML and CSS. This means that Scully built successfully, and that your site is now pre-rendered.

Scully provides a server, so that you can test out your jamstack site after the Scully build. To launch Scully's test server, run the following command:
Expand Down
18 changes: 9 additions & 9 deletions docs/plugin/jsonPlugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export const config: ScullyConfig = {
type: 'json',
userId: {
url: 'http://localhost:8200/users',
property: 'id'
}
}
}
property: 'id',
},
},
},
};
```

Expand All @@ -52,10 +52,10 @@ export const config: ScullyConfig = {
url: 'https://my-api.com/todos',
property: 'id',
headers: {
'API-KEY': '0123456789'
}
}
}
}
'API-KEY': '0123456789',
},
},
},
},
};
```
4 changes: 2 additions & 2 deletions docs/utils.md → docs/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ lang: en
Scully works well in combination with other tools and utilities, for example:

- [Utilities](#utilities)
- [Github Action: Scully Publish](#github-action-scully-publish)
- [Syntax Highlighting Using Prismjs](#syntax-highlighting-using-prismjs)
- [Github Action: Scully Publish](#github-action-scully-publish)
- [Syntax Highlighting Using Prismjs](#syntax-highlighting-using-prismjs)

## Github Action: Scully Publish

Expand Down
7 changes: 4 additions & 3 deletions libs/scully/src/lib/renderPlugins/puppeteerRenderPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,10 @@ export const puppeteerRender = async (route: HandledRoute): Promise<string> => {
throw new Error(`Route "${route.route}" render to ${path}`);
}

const firstTitle = await page.evaluate(
() => document.querySelector('h1').innerText
);
const firstTitle = await page.evaluate(() => {
const d = document.querySelector('h1');
return (d && d.innerText) || '';
});
if (firstTitle === title404) {
logWarn(`Route "${yellow(route.route)}" not provided by angular app`);
}
Expand Down
18 changes: 14 additions & 4 deletions libs/scully/src/lib/utils/serverstuff/handleUnknownRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ export const handleUnknownRoute: RequestHandler = async (req, res, next) => {
if (req.accepts('html')) {
/** only handle 404 on html requests specially */
await loadConfig;
const distIndex = join(
scullyConfig.homeFolder,
scullyConfig.distFolder,
'/index.html'
);
const dist404 = join(
scullyConfig.homeFolder,
scullyConfig.distFolder,
'/404.html'
);
// cmd-line takes precedence over config
const h404 = (handle404.trim() === '' ? scullyConfig.handle404 : handle404)
.trim()
Expand All @@ -24,22 +34,22 @@ export const handleUnknownRoute: RequestHandler = async (req, res, next) => {
case '':
const myHandledRoutes = loadHandledRoutes();
if (myHandledRoutes.includes(req.url)) {
return res.sendFile(join(scullyConfig.outDir, '/index.html'));
return res.sendFile(distIndex);
}
break;
case 'onlybase':
case 'baseonly':
const unhandledRoutes = await handleTravesal();
if (unhandledRoutes.find(matchRoute(req))) {
/** this is a base route known by Scully, just return the index */
return res.sendFile(join(scullyConfig.outDir, '/index.html'));
return res.sendFile(distIndex);
}
/** use fallthrough as all of those are served by the above route-machers, and only here if the route is 404 */
break;
case 'index':
return res.sendFile(join(scullyConfig.outDir, '/index.html'));
return res.sendFile(distIndex);
case '404':
return res.sendFile(join(scullyConfig.outDir, '/404.html'));
return res.sendFile(dist404);
case 'none':
/** let express do its default thing, don't alter behavior */
return next();
Expand Down
13 changes: 9 additions & 4 deletions scully.scully-docs.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ export const config: ScullyConfig = {
projectRoot: './apps/scully-docs/src',
projectName: 'scully-docs',
outDir: './dist/static/doc-sites',
distFolder: './dist/apps/scully-docs',
defaultPostRenderers,
routes: {
'/docs/:slug': {
type: 'contentFolder',
postRenderers: ['docsLink', ...defaultPostRenderers],
slug: {
folder: './docs'
}
}
}
folder: './docs',
},
},
},
puppeteerLaunchOptions: {
defaultViewport: null,
devtools: true,
},
};

0 comments on commit 6ffa567

Please sign in to comment.