fixes to website (#9615)

* fixes

* add changeset

* try something

* try 2

* fix

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: aliabd <ali.si3luwa@gmail.com>
This commit is contained in:
pngwn 2024-10-09 19:52:12 +01:00 committed by GitHub
parent 9af29c8696
commit 204f3e13e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 73 additions and 207 deletions

View File

@ -0,0 +1,5 @@
---
"website": minor
---
feat:fixes to website

View File

@ -18,22 +18,29 @@ def make_dir(root, path):
def download_from_s3(bucket_name, s3_folder, local_dir):
print(
"Downloading templates from S3: "
+ bucket_name
+ "/"
+ s3_folder
+ " to "
+ local_dir
)
print(f"Downloading templates from S3: {bucket_name}/{s3_folder} to {local_dir}")
s3 = boto3.client("s3", config=Config(signature_version=UNSIGNED))
objects = s3.list_objects_v2(Bucket=bucket_name, Prefix=s3_folder)
try:
objects = s3.list_objects_v2(Bucket=bucket_name, Prefix=s3_folder)
except Exception as e:
print(f"Error listing objects in bucket {bucket_name}: {e}")
return
for obj in objects.get("Contents", []):
s3_key = obj["Key"]
local_file_path = os.path.join(local_dir, os.path.relpath(s3_key, s3_folder))
if not os.path.exists(os.path.dirname(local_file_path)):
os.makedirs(os.path.dirname(local_file_path))
s3.download_file(bucket_name, s3_key, local_file_path)
if s3_key.endswith("/"):
continue
try:
os.makedirs(os.path.dirname(local_file_path), exist_ok=True)
s3.download_file(bucket_name, s3_key, local_file_path)
except Exception as e:
print(f"Error downloading {s3_key}: {e}")
print(f"Download process completed for {bucket_name}/{s3_folder}")
def convert_to_pypi_prerelease(version: str) -> str:
@ -63,23 +70,31 @@ def get_latest_release():
.strip("'\n")
)
json.dump(
{
"gradio_install": f"pip install https://gradio-builds.s3.amazonaws.com/{sha}/gradio-{version}-py3-none-any.whl",
"gradio_py_client_install": f"pip install 'gradio-client @ git+https://github.com/gradio-app/gradio@{sha}#subdirectory=client/python'",
"gradio_js_client_install": f"npm install https://gradio-builds.s3.amazonaws.com/{sha}/gradio-client-{js_client_version}.tgz",
"gradio_lite_url": f"https://gradio-lite-previews.s3.amazonaws.com/{sha}"
},
{
"gradio_install": f"pip install https://gradio-builds.s3.amazonaws.com/{sha}/gradio-{version}-py3-none-any.whl",
"gradio_py_client_install": f"pip install 'gradio-client @ git+https://github.com/gradio-app/gradio@{sha}#subdirectory=client/python'",
"gradio_js_client_install": f"npm install https://gradio-builds.s3.amazonaws.com/{sha}/gradio-client-{js_client_version}.tgz",
"gradio_lite_url": f"https://gradio-lite-previews.s3.amazonaws.com/{sha}",
},
j,
)
if not os.path.exists(
make_dir(WEBSITE_DIR, f"src/lib/templates_{version.replace('.', '-')}")
):
print(f"Downloading templates from S3: {version}")
download_from_s3(
"gradio-docs-json",
f"{version}/templates/",
make_dir(WEBSITE_DIR, f"src/lib/templates_{version.replace('.', '-')}"),
)
print("Downloading templates from S3: 4.44.1")
download_from_s3(
"gradio-docs-json",
"4.44.1/templates/",
make_dir(WEBSITE_DIR, "src/lib/templates_4-44-1"),
)
def create_dir_if_not_exists(path):
if not os.path.exists(path):

View File

@ -4,7 +4,7 @@
import { goto } from "$app/navigation";
import { version } from "$lib/json/version.json";
export let choices = [version, "main"];
export let choices = [version, "4.44.1", "main"];
export let value: string = $page.params?.version || version;
export let docs_type = "python";
@ -39,18 +39,8 @@
}`;
function reload() {
if (browser) {
if (is_docs) {
window.location.href = docs_url;
}
if (is_guide) {
window.location.href = guide_url;
}
}
goto(is_docs ? docs_url : guide_url);
}
$: browser && is_docs && goto(docs_url);
$: browser && is_docs && goto(docs_url);
</script>
<svelte:head>

View File

@ -7,11 +7,20 @@ export const prerender = true;
const DOCS_BUCKET = "https://gradio-docs-json.s3.us-west-2.amazonaws.com";
const VERSION = version.version;
let cache = new Map();
async function load_release_docs(
version: string
): Promise<typeof import("$lib/json/docs.json")> {
if (cache.has(version)) {
return cache.get(version);
}
let docs_json = await fetch(`${DOCS_BUCKET}/${version}/docs.json`);
return await docs_json.json();
let json = await docs_json.json();
cache.set(version, json);
return json;
}
async function load_main_docs(): Promise<typeof import("$lib/json/docs.json")> {

View File

@ -1,4 +1,4 @@
import { error } from "@sveltejs/kit";
import { error, redirect } from "@sveltejs/kit";
export async function load({ params, parent }) {
const {
@ -11,6 +11,7 @@ export async function load({ params, parent }) {
const modules : any = import.meta.glob("/src/lib/templates*/gradio/**/*.svx");
let name = params.doc;
let version = params.version || VERSION;
let page_path : string | null = null;
for (const category of pages.gradio) {
@ -22,17 +23,29 @@ export async function load({ params, parent }) {
}
if (page_path === null) {
throw error(404);
if (!params.version) {
throw redirect(308, `/docs/gradio/interface`);
} else {
throw redirect(308, `/${params.version}/docs/gradio/interface`);
}
}
let version_append = on_main ? "/" : "_" + VERSION.replace(/\./g, "-") + "/";
let version_append = on_main ? "/" : "_" + version.replace(/\./g, "-") + "/";
let module;
for (const path in modules) {
if (path.includes(page_path) && path.includes("templates" + version_append)) {
module = await modules[path]();
}
}
if (module === undefined) {
if (!params.version) {
throw redirect(302, `/docs/gradio/interface`);
} else {
throw redirect(302, `/${params.version}/docs/gradio/interface`);
}
}

View File

@ -122,14 +122,18 @@ const config = {
`/main/docs/js`,
`/main/docs/js/storybook`,
`/main/docs/js/`,
...Object.keys(redirects)
...Object.keys(redirects),
`/4.44.1/docs`,
`/4.44.1/guides`
],
handleMissingId: "warn"
},
files: {
lib: "src/lib"
},
adapter: adapter(),
adapter: adapter({
fallback: "404.html"
}),
paths: {
relative: false
}

File diff suppressed because one or more lines are too long