Skip to content

Commit

Permalink
Badge en javascript plutôt (#469)
Browse files Browse the repository at this point in the history
* Getting started badge

* updatr

* badges

* badges

* Corrections

* ipynb
  • Loading branch information
linogaliana committed Dec 10, 2023
1 parent 0bb0254 commit 4c1c22d
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 310 deletions.
37 changes: 0 additions & 37 deletions _quarto.yml
Expand Up @@ -11,43 +11,6 @@ project:
- content/getting-started/05_rappels_types.qmd
- content/getting-started/06_rappels_fonctions.qmd
- content/getting-started/07_rappels_classes.qmd
- content/manipulation/index.qmd
- content/manipulation/01_numpy.qmd
- content/manipulation/02a_pandas_tutorial.qmd
- content/manipulation/02b_pandas_TP.qmd
- content/manipulation/03_geopandas_tutorial.qmd
- content/manipulation/03_geopandas_TP.qmd
- content/manipulation/04a_webscraping_TP.qmd
- content/manipulation/04c_API_TP.qmd
- content/manipulation/04b_regex_TP.qmd
- content/manipulation/07_dask.qmd
- content/visualisation/index.qmd
- content/visualisation/matplotlib.qmd
- content/visualisation/maps.qmd
- content/modelisation/index.qmd
- content/modelisation/0_preprocessing.qmd
- content/modelisation/1_modelevaluation.qmd
- content/modelisation/2_SVM.qmd
- content/modelisation/3_regression.qmd
- content/modelisation/4_featureselection.qmd
- content/modelisation/5_clustering.qmd
- content/modelisation/6_pipeline.qmd
- content/modelisation/7_mlapi.qmd
- content/NLP/index.qmd
- content/NLP/01_intro.qmd
- content/NLP/02_exoclean.qmd
- content/NLP/03_lda.qmd
- content/NLP/04_word2vec.qmd
- content/NLP/05_exo_supp.qmd
- content/modern-ds/index.qmd
- content/modern-ds/continuous_integration.qmd
- content/modern-ds/dallE.qmd
- content/modern-ds/s3.qmd
- content/modern-ds/elastic_approfondissement.qmd
- content/modern-ds/elastic_intro.qmd
- content/git/index.qmd
- content/git/introgit.qmd
- content/git/exogit.qmd
- content/annexes/evaluation.qmd
- content/annexes/corrections.qmd
- content/annexes/evaluation.qmd
Expand Down
166 changes: 166 additions & 0 deletions build/_printBadges.qmd
@@ -0,0 +1,166 @@
```{ojs}
//| echo: false
path = window.location.pathname.replace(".html", ".qmd");
html`${printBadges({fpath: path})}`
```



```{ojs}
//| echo: false
function reminderBadges({
sourceFile = "content/01_toto.Rmd",
type = ['md', 'html'],
split = null,
onyxiaOnly = false,
sspCloudService = "python",
GPU = false,
correction = false
} = {}) {
if (Array.isArray(type)) {
type = type[0];
}
let notebook = sourceFile.replace(/(.Rmd|.qmd)/, ".ipynb");
if (correction) {
notebook = notebook.replace(/content/, "corrections");
} else {
notebook = notebook.replace(/content/, "notebooks");
}
const githubRepoNotebooksSimplified = "github/linogaliana/python-datascientist-notebooks";
const githubAlias = githubRepoNotebooksSimplified.replace("github", "github.com");
const githubRepoNotebooks = `https://${githubAlias}`;
let githubLink, nbviewerLink;
if (notebook === "") {
githubLink = githubRepoNotebooks;
nbviewerLink = `https://nbviewer.jupyter.org/${githubRepoNotebooksSimplified}/tree/main`;
} else {
githubLink = `${githubRepoNotebooks}/blob/main`;
nbviewerLink = `https://nbviewer.jupyter.org/${githubRepoNotebooksSimplified}/blob/main/${notebook}`;
}
const notebookRelPath = `/${notebook}`;
const [section, chapter] = notebook.split("/").slice(-2);
let downloadLink;
if (type === "md") {
downloadLink = `[![Download](https://img.shields.io/badge/Download-Notebook-important?logo=Jupyter)](https://downgit.github.io/#/home?url=${githubLink}${notebookRelPath})`;
} else {
downloadLink = `<a href="https://downgit.github.io/#/home?url=${githubLink}${notebookRelPath}" target="_blank" rel="noopener"><img src="https://img.shields.io/badge/Download-Notebook-important?logo=Jupyter" alt="Download"></a>`;
}
githubLink = `<a href="${githubLink}${notebookRelPath}" class="github"><i class="fab fa-github"></i></a>`;
let visualizeLink;
if (type === "md") {
visualizeLink = `[![nbviewer](https://img.shields.io/badge/Visualize-nbviewer-blue?logo=Jupyter)](${nbviewerLink})`;
} else {
visualizeLink = `<a href="${nbviewerLink}" target="_blank" rel="noopener"><img src="https://img.shields.io/badge/Visualize-nbviewer-blue?logo=Jupyter" alt="nbviewer"></a>`;
}
const sectionLatest = section.split("/").slice(-1)[0];
const chapterNoExtension = chapter.replace(".ipynb", "");
const onyxiaInitArgs = [sectionLatest, chapterNoExtension];
if (correction) {
onyxiaInitArgs.push("correction");
}
const gpuSuffix = GPU ? "-gpu" : "";
const sspcloudJupyterLinkLauncher = `https://datalab.sspcloud.fr/launcher/ide/jupyter-${sspCloudService}${gpuSuffix}?autoLaunch=true&onyxia.friendlyName=%C2%AB${chapterNoExtension}%C2%BB&init.personalInit=%C2%ABhttps%3A%2F%2Fraw.githubusercontent.com%2Flinogaliana%2Fpython-datascientist%2Fmaster%2Fsspcloud%2Finit-jupyter.sh%C2%BB&init.personalInitArgs=%C2%AB${onyxiaInitArgs.join('%20')}%C2%BB&security.allowlist.enabled=false`;
let sspcloudJupyterLink;
if (type === "md") {
sspcloudJupyterLink = `[![Onyxia](https://img.shields.io/badge/SSP%20Cloud-Tester_avec_Jupyter-orange?logo=Jupyter&logoColor=orange)](${sspcloudJupyterLinkLauncher})`;
} else {
sspcloudJupyterLink = `<a href="${sspcloudJupyterLinkLauncher}" target="_blank" rel="noopener"><img src="https://img.shields.io/badge/SSP%20Cloud-Tester_avec_Jupyter-orange?logo=Jupyter&logoColor=orange" alt="Onyxia"></a>`;
}
if (split === 4) {
sspcloudJupyterLink += '<br>';
}
const sspcloudVscodeLinkLauncher = `https://datalab.sspcloud.fr/launcher/ide/vscode-${sspCloudService}${gpuSuffix}?autoLaunch=true&onyxia.friendlyName=%C2%AB${chapterNoExtension}%C2%BB&init.personalInit=%C2%ABhttps%3A%2F%2Fraw.githubusercontent.com%2Flinogaliana%2Fpython-datascientist%2Fmaster%2Fsspcloud%2Finit-vscode.sh%C2%BB&init.personalInitArgs=%C2%AB${onyxiaInitArgs.join('%20')}%C2%BB&security.allowlist.enabled=false`;
let sspcloudVscodeLink;
if (type === "md") {
sspcloudVscodeLink = `[![Onyxia](https://img.shields.io/badge/SSP%20Cloud-Tester_avec_VSCode-blue?logo=visualstudiocode&logoColor=blue)](${sspcloudVscodeLinkLauncher})`;
} else {
sspcloudVscodeLink = `<a href="${sspcloudVscodeLinkLauncher}" target="_blank" rel="noopener"><img src="https://img.shields.io/badge/SSP%20Cloud-Tester_avec_VSCode-blue?logo=visualstudiocode&logoColor=blue" alt="Onyxia"></a>`;
}
if (split === 5) {
sspcloudVscodeLink += '<br>';
}
let colabLink;
if (type === "md") {
colabLink = `[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](http://colab.research.google.com/${githubRepoNotebooksSimplified}/blob/main${notebookRelPath})`;
} else {
colabLink = `<a href="https://colab.research.google.com/${githubRepoNotebooksSimplified}/blob/main${notebookRelPath}" target="_blank" rel="noopener"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"></a>`;
}
if (split === 7) {
colabLink += '<br>';
}
let vscodeLink;
if (type === "md") {
vscodeLink = `[![githubdev](https://img.shields.io/static/v1?logo=visualstudiocode&label=&message=Open%20in%20Visual Studio Code&labelColor=2c2c32&color=007acc&logoColor=007acc)](https://github.dev/linogaliana/python-datascientist-notebooks${notebookRelPath})`;
} else {
vscodeLink = `<a href="https://github.dev/linogaliana/python-datascientist-notebooks${notebookRelPath}" target="_blank" rel="noopener"><img src="https://img.shields.io/static/v1?logo=visualstudiocode&label=&message=Open%20in%20Visual%20Studio%20Code&labelColor=2c2c32&color=007acc&logoColor=007acc" alt="githubdev"></a></p>`;
}
const badges = [
githubLink, downloadLink,
visualizeLink, sspcloudJupyterLink,
sspcloudVscodeLink
];
if (!onyxiaOnly) {
badges.push(colabLink, vscodeLink);
}
let result = badges.join("\n");
if (type === "html") {
result = `<p class="badges">${result}</p>`;
}
if (onyxiaOnly) {
result = `${sspcloudJupyterLink}${sspcloudVscodeLink}`;
}
return result;
}
function printBadges({
fpath,
onyxiaOnly = false,
split = 5,
type = "html",
sspCloudService = "python",
GPU = false,
correction = false
} = {}) {
const badges = reminderBadges({
sourceFile: fpath,
type: type,
split: split,
onyxiaOnly: onyxiaOnly,
sspCloudService: sspCloudService,
GPU: GPU,
correction: correction
});
return badges
}
// Example usage:
// printBadges({ fpath: "content/getting-started/05_rappels_types.qmd", onyxiaOnly: false, split: 5, type: "html", sspCloudService: "python", GPU: false, correction: false });
```

0 comments on commit 4c1c22d

Please sign in to comment.