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

feat: add "Examples" navigation link #26

Merged
merged 5 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ module.exports = {
docId: 'api/app',
position: 'left',
},
{
label: 'Examples',
type: 'doc',
docId: 'how-to/examples',
position: 'left',
},
{
href: 'https://github.com/electron/electron',
label: 'GitHub',
Expand Down
4 changes: 4 additions & 0 deletions scripts/pre-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const { copy, download } = require('./tasks/download-docs');
const { addFrontmatter } = require('./tasks/add-frontmatter');
const { createSidebar } = require('./tasks/create-sidebar');
const { fixContent } = require('./tasks/md-fixers');
const { copyNewContent } = require('./tasks/copy-new-content');

const DOCS_FOLDER = 'docs';
// const BLOG_FOLDER = 'blog';
Expand Down Expand Up @@ -63,6 +64,9 @@ const start = async (localElectron) => {
// downloadMatch: 'data/blog',
// });

console.log('Copying new content');
await copyNewContent(DOCS_FOLDER);

console.log('Fixing markdown');
await fixContent(DOCS_FOLDER);

Expand Down
21 changes: 21 additions & 0 deletions scripts/tasks/copy-new-content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const fs = require('fs').promises;
const path = require('path');

const newContent = new Map([['how-to-examples.md', 'how-to/examples.md']]);

/**
* Copies the new content files to the destination
* @param {string} destination
*/
const copyNewContent = async (destination) => {
for (const [source, target] of newContent) {
await fs.copyFile(
path.join(__dirname, source),
path.join(destination, target)
);
}
};

module.exports = {
copyNewContent,
};
38 changes: 38 additions & 0 deletions scripts/tasks/how-to-examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: 'Examples'
description: 'A set of examples for common Electron features'
slug: examples
hide_title: false
---

# Examples

In this section, we have collected a set of guides for common features
that you may want to implement in your Electron application. Each guide
contains a practical example in a minimal, self-contained example app.
The easiest way to run these examples is by downloading [Electron Fiddle][fiddle].

Once Fiddle is installed, you can press on the "Open in Fiddle" button that you
will find below code samples like the following one:

```fiddle docs/fiddles/quick-start
window.addEventListener('DOMContentLoaded', () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector)
if (element) element.innerText = text
}

for (const type of ['chrome', 'node', 'electron']) {
replaceText(`${type}-version`, process.versions[type])
}
})
```

## How to...?

You can find the full list of "How to?" in the sidebar. If there is
something that you would like to do that is not documented, please join
our [discord server][] and let us know!

[discord server]: https://discord.com/invite/electron
molant marked this conversation as resolved.
Show resolved Hide resolved
[fiddle]: https://www.electronjs.org/fiddle
1 change: 1 addition & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ module.exports = {
type: 'category',
label: 'How To',
items: [
'how-to/examples',
'how-to/dark-mode',
'how-to/desktop-environment-integration',
'how-to/fuses',
Expand Down