Skip to content
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

Improve inline and google search results #1169

Merged
merged 3 commits into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ export const createPlaygroundExamplePages = async (
.replace(/\+/g, "-")

const language = rPath.split("/")[0]
const postLangPath = rPath
.split("/")
.slice(1)
.map(idize)
.join("/")
const postLangPath = rPath.split("/").slice(1).map(idize).join("/")

const langPrefix = language === "en" ? "" : language
const newPagePath = langPrefix + "/play/" + postLangPath
Expand All @@ -64,14 +60,11 @@ export const createPlaygroundExamplePages = async (
const exampleCodePath = path.join(appRoot, "playground-examples", "copy", rPath)
const code = fs.readFileSync(exampleCodePath, "utf8")

const id = postLangPath
.split("/")
.slice(-1)[0]
.split(".")[0]
const id = postLangPath.split("/").slice(-1)[0].split(".")[0]

const { inlineTitle, compilerSettings } = getCompilerDetailsFromCode(code)
createPage({
path: newPagePath,
path: newPagePath + ".html",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prev: https://www.typescriptlang.org/ja/play/typescript/language-extensions/types-vs-interfaces.ts
Post: https://www.typescriptlang.org/ja/play/typescript/language-extensions/types-vs-interfaces.ts.html

I think it's safe to assume that search engines don't try read .ts or .js files.

component: playPage,
context: {
name,
Expand Down Expand Up @@ -106,11 +99,11 @@ const getCompilerDetailsFromCode = (contents: string) => {

if (contents.startsWith("//// {")) {
// convert windows newlines to linux new lines
const preJSON = contents.replace(/\r\n/g, "\n").split("//// {")[1].split("}\n")[0]
contents = contents
.split("\n")
.slice(1)
.join("\n")
const preJSON = contents
.replace(/\r\n/g, "\n")
.split("//// {")[1]
.split("}\n")[0]
contents = contents.split("\n").slice(1).join("\n")
const code = "({" + preJSON + "})"

try {
Expand Down
3 changes: 2 additions & 1 deletion packages/typescriptlang-org/src/templates/play-example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const Play = (props: Props) => {

return (
<Layout title={i("playground_example_prefix") + props.pageContext.title} description={i("head_playground_description")} lang={props.pageContext.lang} allSitePage={props.data.allSitePage}>
<div className="raised main-content-block" >
<div className="raised main-content-block markdown">
<h2>{props.pageContext.title}</h2>
<div style={{ maxWidth: "800px", margin: "0 auto", padding: "80px" }}>
<p dangerouslySetInnerHTML={{ __html: props.pageContext.html! }} />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const TSConfigReferenceTemplateComponent = (props) => {

return (
<Layout title={i("tsconfig_title")} description={i("tsconfig_description")} lang={props.pageContext.locale} allSitePage={props.data.allSitePage}>
<div className="tsconfig raised main-content-block">
<div className="tsconfig raised main-content-block markdown">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<div dangerouslySetInnerHTML={{ __html: post.html! }} />
</div>
</Layout>
Expand Down