Skip to content

Commit bdc68de

Browse files
pretty URLs
1 parent 59b0b72 commit bdc68de

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

packages/cli/src/lifecycles/graph.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const createGraphFromPages = async (pagesDir, config) => {
5656
let fileRoute = subDir.substring(seperatorIndex, subDir.length - 3);
5757

5858
// determine if this is an index file, if so set route to '/'
59-
let route = fileRoute === '/index' ? '/' : fileRoute;
59+
let route = fileRoute === '/index' ? '/' : `${fileRoute}/`;
6060

6161
// check if additional nested directories
6262
if (seperatorIndex > 0) {
@@ -164,7 +164,7 @@ const createGraphFromPages = async (pagesDir, config) => {
164164
// route,
165165
// template,
166166
filePath,
167-
route: file === 'index.html' ? '/' : file
167+
route: file === 'index.html' ? '/' : `${file}/`
168168
// fileName,
169169
// relativeExpectedPath,
170170
// title

packages/cli/src/lifecycles/serve.js

+18-10
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@ function getDevServer(compilation) {
2525
// console.debug('URL', ctx.request.url);
2626

2727
// TODO filter out node modules, only page / user requests from brower
28-
if (ctx.request.url.endsWith('/')) {
28+
// TODO make sure this only happens for "pages", nor partials or fixtures, templates, et)
29+
if (ctx.request.url.endsWith('/') || ctx.request.url.endsWith('.html')) {
2930
// console.log('URL ends with /');
3031
// TODO get port from compilation
31-
ctx.redirect(`http://localhost:1984${ctx.request.url}index.html`);
32-
}
33-
34-
// make sure this only happens for "pages", nor partials or fixtures, templates, et)
35-
if (ctx.request.url.indexOf('.html') >= 0) {
32+
// ctx.redirect(`http://localhost:1984${ctx.request.url}index.html`);
33+
// }
3634
let title = config.title;
3735

3836
const metaOutletContent = config.meta.map(item => {
@@ -48,11 +46,14 @@ function getDevServer(compilation) {
4846
}).join('\n');
4947

5048
// TODO get pages path from compilation
51-
const barePath = `${userWorkspace}/pages${ctx.request.url.replace('.html', '')}`;
49+
const barePath = ctx.request.url.endsWith('/')
50+
? `${userWorkspace}/pages${ctx.request.url}index`
51+
: `${userWorkspace}/pages${ctx.request.url.replace('.html', '')}`;
52+
5253
// console.debug('bare path', barePath);
5354

5455
let contents = `
55-
<!DOCTYPE html>
56+
<!DOCTYPE html>
5657
<html lang="en" prefix="og:http://ogp.me/ns#">
5758
<head>
5859
<title>${title}</title>
@@ -68,14 +69,21 @@ function getDevServer(compilation) {
6869
</html>
6970
`;
7071

72+
7173
if (fs.existsSync(`${barePath}.html`)) {
7274
// console.debug('this route exists as HTML');
7375
contents = await fsp.readFile(`${barePath}.html`, 'utf-8');
74-
} else if (fs.existsSync(`${barePath}.md`) || fs.existsSync(`${userWorkspace}/pages${ctx.request.url.replace('/index.html', '.md')}`)) {
76+
} else if (fs.existsSync(`${barePath}.md`)
77+
|| fs.existsSync(`${userWorkspace}/pages${ctx.request.url.replace('/index.html', '.md')}`)
78+
|| fs.existsSync(`${barePath.replace('/index', '.md')}`)) {
79+
7580
// TODO all this lookup could probably be handled a bit more gracefully perhaps?
81+
// console.debug('this route exists as markdown');
7682
const markdownPath = fs.existsSync(`${barePath}.md`)
7783
? `${barePath}.md`
78-
: `${userWorkspace}/pages${ctx.request.url.replace('/index.html', '.md')}`;
84+
: fs.existsSync(`${barePath.replace('/index', '.md')}`)
85+
? `${barePath.replace('/index', '.md')}`
86+
: `${userWorkspace}/pages${ctx.request.url.replace('/index.html', '.md')}`;
7987
const markdownContents = await fsp.readFile(markdownPath, 'utf-8');
8088

8189
// console.debug('this route exists as a markdown file', markdownPath);

www/components/banner/banner.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class Banner extends LitElement {
7171
7272
<h3>The static site generator for your. . . <br /><span class="${this.animateState}">${currentProjectType}.</span></h3>
7373
74-
<eve-button size="md" href="/getting-started" style="${buttonCss}">Get Started</eve-button>
74+
<eve-button size="md" href="/getting-started/" style="${buttonCss}">Get Started</eve-button>
7575
</div>
7676
</eve-container>
7777
</div>

0 commit comments

Comments
 (0)