-
-
Notifications
You must be signed in to change notification settings - Fork 761
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
feat: Public dir support #569
Changes from 12 commits
0d32850
30857d5
ce49675
e15767c
7654b43
5672a4d
3d1f4fa
9b24341
ce0bfd6
ae482ce
91864e8
38e560a
6173981
ccdc898
9fd18f7
229365f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#__next { | ||
font-family: 'Open Sans', sans-serif; | ||
text-align: center; | ||
background-image: linear-gradient(to left top, #ffffff, #f5f5f5, #eaeaea, #e0e0e0, #d6d6d6); | ||
display: flex; | ||
flex-direction: column; | ||
min-height: 100vh; | ||
min-width: 100vw; | ||
} | ||
|
||
h1, | ||
h2 { | ||
font-family: 'Oswald', sans-serif; | ||
} | ||
|
||
h1 { | ||
font-size: 3rem; | ||
margin: 5rem 0; | ||
} | ||
h2 { | ||
min-width: 18rem; | ||
font-size: 2rem; | ||
opacity: 0.3; | ||
} | ||
|
||
p { | ||
line-height: 1.65em; | ||
} | ||
p:nth-child(2) { | ||
font-style: italic; | ||
opacity: 0.65; | ||
margin-top: 1rem; | ||
} | ||
|
||
a.github { | ||
position: fixed; | ||
top: 0.5rem; | ||
right: 0.75rem; | ||
font-size: 4rem; | ||
color: #888; | ||
opacity: 0.8; | ||
} | ||
a.github:hover { | ||
opacity: 1; | ||
} | ||
|
||
button { | ||
display: inline-block; | ||
vertical-align: bottom; | ||
outline: 0; | ||
text-decoration: none; | ||
cursor: pointer; | ||
padding: .4rem; | ||
background-color: rgba(255, 255, 255, 0.5); | ||
box-sizing: border-box; | ||
font-size: 1em; | ||
font-family: inherit; | ||
border-radius: 3px; | ||
margin: .1rem; | ||
transition: box-shadow .2s ease; | ||
user-select: none; | ||
line-height: 2.5em; | ||
min-height: 40px; | ||
padding: 0 .8em; | ||
border: 0; | ||
color: inherit; | ||
position: relative; | ||
transform: translateZ(0); | ||
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, .26); | ||
margin: 0.8rem; | ||
} | ||
|
||
button:hover, | ||
button:focus { | ||
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, .4); | ||
} | ||
|
||
main { | ||
display: flex; | ||
flex-direction: column; | ||
flex: 1; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
footer { | ||
background-color: rgba(255, 255, 255, 0.5); | ||
width: 100vw; | ||
padding: 3rem 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"h1": "Ein einfaches Beispiel", | ||
"change-locale": "Wechseln Locale", | ||
"to-second-page": "Zur zweiten Seite", | ||
"error-with-status": "Auf dem Server ist ein Fehler ({{statusCode}}) aufgetreten", | ||
"error-without-status": "Auf dem Server ist ein Fehler aufgetreten" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"description": "Dies ist eine Nicht-Seitenkomponente, die einen eigenen Namespace erfordert" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"h1": "Eine zweite Seite, um das Routing zu demonstrieren", | ||
"back-to-home": "Zurück zur Hauptseite" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"h1": "A simple example", | ||
"change-locale": "Change locale", | ||
"to-second-page": "To second page", | ||
"error-with-status": "A {{statusCode}} error occurred on server", | ||
"error-without-status": "An error occurred on the server" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"description": "This is a non-page component that requires its own namespace" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"h1": "A second page, to demonstrate routing", | ||
"back-to-home": "Back to home" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import defaultConfig from './default-config' | ||
import { isServer } from '../utils' | ||
import { consoleMessage, isServer } from '../utils' | ||
|
||
const deepMergeObjects = ['backend', 'detection'] | ||
const dedupe = (names) => names.filter((v,i) => names.indexOf(v) === i) | ||
const STATIC_LOCALE_PATH = 'static/locales' | ||
|
||
export default (userConfig) => { | ||
|
||
|
@@ -33,36 +34,53 @@ export default (userConfig) => { | |
|
||
const fs = eval("require('fs')") | ||
const path = require('path') | ||
let serverLocalePath = localePath | ||
|
||
// Validate defaultNS | ||
// https://github.com/isaachinman/next-i18next/issues/358 | ||
if (process.env.NODE_ENV !== 'production' && typeof combinedConfig.defaultNS === 'string') { | ||
const defaultNSPath = path.join(process.cwd(), `${localePath}/${defaultLanguage}/${combinedConfig.defaultNS}.${localeExtension}`) | ||
const defaultFile = `/${defaultLanguage}/${combinedConfig.defaultNS}.${localeExtension}` | ||
const defaultNSPath = path.join(process.cwd(), localePath, defaultFile) | ||
const defaultNSExists = fs.existsSync(defaultNSPath) | ||
if (!defaultNSExists) { | ||
throw new Error(`Default namespace not found at ${defaultNSPath}`) | ||
// if defaultNS doesn't exist, try to fall back to the deprecated static folder | ||
// https://github.com/isaachinman/next-i18next/issues/523 | ||
const staticDirPath = path.join(process.cwd(), STATIC_LOCALE_PATH, defaultFile) | ||
const staticDirExists = fs.existsSync(staticDirPath) | ||
if (staticDirExists) { | ||
consoleMessage('warn', 'Falling back to /static folder, deprecated in next@9.1.*', combinedConfig) | ||
serverLocalePath = STATIC_LOCALE_PATH | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am just now realising that this fallback will only take place in non-production modes. Wouldn't that effectively break all currently-deployed apps where people rely on the default value of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah you're right, will look at this again in the morning. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the break, holidays and work and what not. What was the original reason for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No problem. Yes that's correct - this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved the production check to just before the error throw, hopefully that sorts things. |
||
} else { | ||
throw new Error(`Default namespace not found at ${defaultNSPath}`) | ||
} | ||
} | ||
} | ||
|
||
// Set server side backend | ||
combinedConfig.backend = { | ||
loadPath: path.join(process.cwd(), `${localePath}/${localeStructure}.${localeExtension}`), | ||
addPath: path.join(process.cwd(), `${localePath}/${localeStructure}.missing.${localeExtension}`), | ||
loadPath: path.join(process.cwd(), `${serverLocalePath}/${localeStructure}.${localeExtension}`), | ||
addPath: path.join(process.cwd(), `${serverLocalePath}/${localeStructure}.missing.${localeExtension}`), | ||
} | ||
|
||
// Set server side preload (languages and namespaces) | ||
combinedConfig.preload = allLanguages | ||
if (!combinedConfig.ns) { | ||
const getAllNamespaces = p => fs.readdirSync(p).map(file => file.replace(`.${localeExtension}`, '')) | ||
combinedConfig.ns = getAllNamespaces(path.join(process.cwd(), `${localePath}/${defaultLanguage}`)) | ||
combinedConfig.ns = getAllNamespaces(path.join(process.cwd(), `${serverLocalePath}/${defaultLanguage}`)) | ||
} | ||
|
||
} else { | ||
|
||
let clientLocalePath = localePath | ||
// remove public/ prefix from client site config | ||
if (localePath.startsWith('public/')) { | ||
clientLocalePath = localePath.replace(/^public\//, '') | ||
} | ||
|
||
// Set client side backend | ||
combinedConfig.backend = { | ||
loadPath: `/${localePath}/${localeStructure}.${localeExtension}`, | ||
addPath: `/${localePath}/${localeStructure}.missing.${localeExtension}`, | ||
loadPath: `/${clientLocalePath}/${localeStructure}.${localeExtension}`, | ||
addPath: `/${clientLocalePath}/${localeStructure}.missing.${localeExtension}`, | ||
} | ||
|
||
combinedConfig.ns = [combinedConfig.defaultNS] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again wondering why this isn't
public/static
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be public/static, also the create-config.test should be changed to public/static on lines 115-116.
Looks like process.env.NODE_ENV is always 'production' in the create-config.test even with
NODE_ENV=test jest
so the test never runs theValidate defaultNS
block and serverLocalePath is just whatever the test-helpers userConfig.localePath is set to. I'm not sure why NODE_ENV is production atm and interested to see if you see the same thing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it looks like it's due to this hacky setup.
We should instead capture the original value in a var, and reassign before the end of the test:
Modifying globals in tests is almost always problematic!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @capellini
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @isaachinman - do you need something from me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tagged you to notify you that we'll most likely need to update these tests. If @nathanfriemel is happy to do the work, I don't think we need anything!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I'm here to assist, if needed. Just let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved the conflicts, want me to go ahead and change static to public/static?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went ahead and changed to public/static