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

"Fix JS icon 404 issue and add copy button to homepage code display" #181

Merged
merged 6 commits into from
Sep 2, 2024
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
4 changes: 2 additions & 2 deletions docs/start/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sidebar_position: 1
```java
import java.util.List;
import java.util.Arrays;
import io.fury.*;
import org.apache.fury.*;

public class Example {
public static void main(String[] args) {
Expand All @@ -36,7 +36,7 @@ public class Example {

```java
import com.google.common.collect.ImmutableMap;
import io.fury.*;
import org.apache.fury.*;

import java.util.Map;

Expand Down
67 changes: 43 additions & 24 deletions src/components/HomePageLanguageCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,63 @@ export const HomePageLanguageCard = () => (
boxShadow: "0 4px 8px rgba(0, 0, 0, 0.1)",
}}
>
<Card.Grid style={gridStyle} onClick={() => {
window.location.href =
"https://fury.apache.org/docs/start/usage/#java-serialization";
}}>
<Card.Grid
style={gridStyle}
onClick={() => {
window.location.href =
"https://fury.apache.org/docs/start/usage/#java-serialization";
}}
>
<img src="..//java.svg" style={imageStyle} />
Java
</Card.Grid>
<Card.Grid style={gridStyle} onClick={() => {
window.location.href =
"https://fury.apache.org/docs/start/usage/#python";
}}>
<Card.Grid
style={gridStyle}
onClick={() => {
window.location.href =
"https://fury.apache.org/docs/start/usage/#python";
}}
>
<img src="..//python.svg" style={imageStyle} />
Python
</Card.Grid>
<Card.Grid style={gridStyle} onClick={() => {
window.location.href =
"https://fury.apache.org/docs/start/usage/#golang";
}}>
<Card.Grid
style={gridStyle}
onClick={() => {
window.location.href =
"https://fury.apache.org/docs/start/usage/#golang";
}}
>
<img src="..//golang.svg" style={imageStyle} />
Golang
</Card.Grid>
<Card.Grid style={gridStyle} onClick={() => {
window.location.href =
"https://fury.apache.org/docs/start/usage/#javascript";
}}>
<img src="..//javascript.svg" style={imageStyle} />
<Card.Grid
style={gridStyle}
onClick={() => {
window.location.href =
"https://fury.apache.org/docs/start/usage/#javascript";
}}
>
<img src="..//JavaScript.svg" style={imageStyle} />
JavaScript
</Card.Grid>
<Card.Grid style={gridStyle} onClick={() => {
window.location.href = "https://fury.apache.org/docs/start/usage/#rust";
}}>
<Card.Grid
style={gridStyle}
onClick={() => {
window.location.href =
"https://fury.apache.org/docs/start/usage/#rust";
}}
>
<img src="..//Rust.svg" style={imageStyle} />
Rust
</Card.Grid>
<Card.Grid style={gridStyle} onClick={() => {
window.location.href =
"https://fury.apache.org/docs/start/usage/#crosslanguage-serialization";
}}>
<Card.Grid
style={gridStyle}
onClick={() => {
window.location.href =
"https://fury.apache.org/docs/start/usage/#crosslanguage-serialization";
}}
>
<img src="..//more.svg" style={imageStyle} />
More
</Card.Grid>
Expand Down
37 changes: 34 additions & 3 deletions src/components/HomepageCode/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from "react";
import React, { useState } from "react";
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
import { dracula } from "react-syntax-highlighter/dist/esm/styles/prism";

export const HomepageCodeDisplay = () => {
const [copySuccess, setCopySuccess] = useState("");
const codeString = `import java.util.List;
import java.util.Arrays;
import org.apache.fury.*;
Expand All @@ -28,6 +29,18 @@ public class Example {
}
`;

const copyToClipboard = () => {
navigator.clipboard.writeText(codeString).then(
() => {
setCopySuccess("Copied!");
setTimeout(() => setCopySuccess(""), 2000); // 清除复制成功的提示
},
(err) => {
setCopySuccess("Failed to copy!");
}
);
};

return (
<>
<div
Expand All @@ -49,14 +62,32 @@ public class Example {
</div>
<div
style={{
position: "relative", // 为绝对定位的按钮提供相对参考
padding: "12px",
justifyContent: "flex-end",
backgroundColor: "#2d2d2d",
borderRadius: "5px",
width: "50%",
height: "auto",
width: "50%",
height: "auto",
}}
>
{/* 复制按钮 */}
<button
onClick={copyToClipboard}
style={{
position: "absolute",
top: "10px",
right: "10px",
backgroundColor: "#444",
color: "#fff",
border: "none",
borderRadius: "5px",
padding: "5px 10px",
cursor: "pointer",
}}
>
{copySuccess ? copySuccess : "Copy"}
</button>
<SyntaxHighlighter
language="java"
style={dracula}
Expand Down
3 changes: 2 additions & 1 deletion static/JavaScript.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading