Skip to content

Commit 711167c

Browse files
committed
style: use short variants of language markers
1 parent 094b14f commit 711167c

File tree

99 files changed

+505
-505
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+505
-505
lines changed

sources/academy/glossary/concepts/css_selectors.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,39 @@ Some of the most common types of CSS selectors are:
1717

1818
This is used to select elements by their tag name. For example, to select all `<p>` elements, you would use the `p` selector.
1919

20-
```javascript
20+
```js
2121
const paragraphs = document.querySelectorAll('p');
2222
```
2323

2424
### Class selector
2525

2626
This is used to select elements by their class attribute. For example, to select all elements with the class of `highlight`, you would use the `.highlight` selector.
2727

28-
```javascript
28+
```js
2929
const highlightedElements = document.querySelectorAll('.highlight');
3030
```
3131

3232
### ID selector
3333

3434
This is used to select an element by its `id` attribute. For example, to select an element with the id of `header`, you would use the `#header` selector.
3535

36-
```javascript
36+
```js
3737
const header = document.querySelector(`#header`);
3838
```
3939

4040
### Attribute selector
4141

4242
This is used to select elements based on the value of an attribute. For example, to select all elements with the attribute `data-custom` whose value is `yes`, you would use the `[data-custom="yes"]` selector.
4343

44-
```javascript
44+
```js
4545
const customElements = document.querySelectorAll('[data-custom="yes"]');
4646
```
4747

4848
### Chaining selectors
4949

5050
You can also chain multiple selectors together to select elements more precisely. For example, to select an element with the class `highlight` that is inside a `<p>` element, you would use the `p.highlight` selector.
5151

52-
```javascript
52+
```js
5353
const highlightedParagraph = document.querySelectorAll('p.highlight');
5454
```
5555

sources/academy/glossary/concepts/html_elements.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ You can also add **attributes** to an element to provide additional information
1919

2020
In JavaScript, you can use the **DOM** (Document Object Model) to interact with elements on a web page. For example, you can use the [`querySelector()` method](./querying_css_selectors.md) to select an element by its [CSS selector](./css_selectors.md), like this:
2121

22-
```javascript
22+
```js
2323
const myElement = document.querySelector('#myId');
2424
```
2525

2626
You can also use `getElementById()` method to select an element by its `id`, like this:
2727

28-
```javascript
28+
```js
2929
const myElement = document.getElementById('myId');
3030
```
3131

3232
You can also use `getElementsByTagName()` method to select all elements of a certain type, like this:
3333

34-
```javascript
34+
```js
3535
const myElements = document.getElementsByTagName('p');
3636
```
3737

sources/academy/glossary/concepts/querying_css_selectors.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ slug: /concepts/querying-css-selectors
1111

1212
Here's an example of how you can use it:
1313

14-
```javascript
14+
```js
1515
const firstButton = document.querySelector('button');
1616
```
1717

@@ -21,15 +21,15 @@ This will select the first button element on the page and store it in the variab
2121

2222
Here's an example of how you can use it:
2323

24-
```javascript
24+
```js
2525
const buttons = document.querySelectorAll('button');
2626
```
2727

2828
This will select all button elements on the page and store them in the variable "buttons".
2929

3030
Both functions can be used to access and manipulate the elements in the web page. Here's an example on how you can use it to extract the text of all buttons.
3131

32-
```javascript
32+
```js
3333
const buttons = document.querySelectorAll('button');
3434
const buttonTexts = buttons.forEach((button) => button.textContent);
3535
```

sources/academy/platform/deploying_your_code/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ For this section, we'll be turning this example project into an actor:
4747
<Tabs groupId="main">
4848
<TabItem value="JavaScript" label="JavaScript">
4949

50-
```javascript
50+
```js
5151
// index.js
5252
const addAllNumbers = (...nums) => nums.reduce((total, curr) => total + curr, 0);
5353

sources/academy/platform/deploying_your_code/inputs_outputs.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ npm install apify
3939

4040
Now, let's import `Actor` from `apify` and use the `Actor.getInput()` function to grab our input.
4141

42-
```javascript
42+
```js
4343
// index.js
4444
import { Actor } from 'apify';
4545

@@ -67,7 +67,7 @@ We'll now add an **INPUT.json** file within **storage/key_value_stores/default**
6767

6868
Then we can add our example project code from earlier. It will grab the input and use it to generate a solution which is logged into the console.
6969

70-
```javascript
70+
```js
7171
// index.js
7272
import { Actor } from 'apify';
7373

@@ -137,7 +137,7 @@ Similarly to reading input, you can write the actor's output either by using the
137137

138138
In the SDK, we can write to the dataset with the `Actor.pushData()` function. Let's go ahead and write the solution of the `addAllNumbers()` function to the dataset store using this function:
139139

140-
```javascript
140+
```js
141141
// index.js
142142

143143
// This is our example project code from earlier.

sources/academy/platform/deploying_your_code/output_schema.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Also, if your desired label has the same name as the defined object key, then yo
145145

146146
The matching object for the Zappos Scraper shown in the example above will look something like this:
147147

148-
```javascript
148+
```js
149149
const results = {
150150
url: request.loadedUrl,
151151
imgUrl: $('#stage button[data-media="image"] img[itemprop="image"]').attr('src'),

sources/academy/platform/expert_scraping_with_apify/solutions/handling_migrations.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Let's first head into our **demo-actor** and create a new file named **asinTrack
1515

1616
Here's the skeleton of our class:
1717

18-
```javascript
18+
```js
1919
// asinTracker.js
2020
class ASINTracker {
2121
constructor() {
@@ -48,7 +48,7 @@ Multiple techniques exist for storing data in memory; however, this is the most
4848

4949
Here is our updated **routes.js** file which is now utilizing this utility class to track the number of offers for each product ASIN:
5050

51-
```javascript
51+
```js
5252
// routes.js
5353
import { createCheerioRouter } from '@crawlee/cheerio';
5454
import { BASE_URL, OFFERS_URL, labels } from './constants';
@@ -131,7 +131,7 @@ The **persistState** event is automatically fired (by default) every 60 seconds
131131

132132
In order to persist our ASIN tracker object, let's use the `Actor.on` function to listen for the **persistState** event and store it in the key-value store each time it is emitted.
133133

134-
```javascript
134+
```js
135135
// asinTracker.js
136136
import { Actor } from 'apify';
137137
// We've updated our constants.js file to include the name
@@ -168,7 +168,7 @@ Great! Now our state will be persisted every 60 seconds in the key-value store.
168168

169169
In order to fix this, let's create a method called `initialize` which will be called at the very beginning of the actor's run, and will check the key-value store for a previous state under the key **ASIN-TRACKER**. If a previous state does live there, then it will update the class' `state` variable with the value read from the key-value store:
170170

171-
```javascript
171+
```js
172172
// asinTracker.js
173173
import { Actor } from 'apify';
174174
import { ASIN_TRACKER } from './constants';
@@ -209,7 +209,7 @@ module.exports = new ASINTracker();
209209

210210
We'll now call this function at the top level of the **main.js** file to ensure it is the first thing that gets called when the actor starts up:
211211

212-
```javascript
212+
```js
213213
// main.js
214214

215215
// ...

sources/academy/platform/expert_scraping_with_apify/solutions/integrating_webhooks.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Cool! Now, we're ready to get started.
2121

2222
First of all, we should clear out any of the boilerplate code within **main.js** to get a clean slate:
2323

24-
```javascript
24+
```js
2525
// main.js
2626
import { Actor } from 'apify';
2727

@@ -34,21 +34,21 @@ await Actor.exit();
3434

3535
We'll be passing the ID of the Amazon actor's default dataset along to the new actor, so we can expect that as an input:
3636

37-
```javascript
37+
```js
3838
const { datasetId } = await Actor.getInput();
3939
const dataset = await Actor.openDataset(datasetId);
4040
// ...
4141
```
4242

4343
Next, we'll grab hold of the dataset's items with the `dataset.getData()` function:
4444

45-
```javascript
45+
```js
4646
const { items } = await dataset.getData();
4747
```
4848

4949
While several methods can achieve the goal output of this actor, using the [`Array.reduce()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce) is the most concise approach
5050

51-
```javascript
51+
```js
5252
const filtered = items.reduce((acc, curr) => {
5353
// Grab the price of the item matching our current
5454
// item's ASIN in the map. If it doesn't exist, set
@@ -70,13 +70,13 @@ const filtered = items.reduce((acc, curr) => {
7070
7171
The results should be an array, so finally, we can take the map we just created and push an array of all of its values to the actor's default dataset:
7272
73-
```javascript
73+
```js
7474
await Actor.pushData(Object.values(filtered));
7575
```
7676
7777
Our final code looks like this:
7878
79-
```javascript
79+
```js
8080
import { Actor } from 'apify';
8181

8282
await Actor.init();

sources/academy/platform/expert_scraping_with_apify/solutions/rotating_proxies.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ slug: /expert-scraping-with-apify/solutions/rotating-proxies
1313

1414
If you take a look at our current code for the Amazon scraping actor, you might notice this snippet:
1515

16-
```javascript
16+
```js
1717
const proxyConfiguration = await Actor.createProxyConfiguration({
1818
groups: ['RESIDENTIAL'],
1919
});
@@ -29,7 +29,7 @@ In order to rotate sessions, we must utilize the [**SessionPool**](https://crawl
2929

3030
Let's go ahead and add a **sessionPoolOptions** key to our crawler's configuration so that we can modify the default settings:
3131

32-
```javascript
32+
```js
3333
const crawler = new CheerioCrawler({
3434
requestList,
3535
requestQueue,
@@ -52,7 +52,7 @@ const crawler = new CheerioCrawler({
5252

5353
Now, we'll use the **maxUsageCount** key to force each session to be thrown away after 5 uses and **maxErrorScore**** to trash a session once it receives an error.
5454

55-
```javascript
55+
```js
5656
const crawler = new CheerioCrawler({
5757
requestList,
5858
requestQueue,
@@ -75,7 +75,7 @@ And that's it! We've successfully configured the session pool to match the task'
7575

7676
The final requirement was to only use proxies from the US. Back in our **ProxyConfiguration**, we just need to add the **countryCode** key and set it to **US**:
7777

78-
```javascript
78+
```js
7979
const proxyConfiguration = await Actor.createProxyConfiguration({
8080
groups: ['RESIDENTIAL'],
8181
countryCode: 'US',

sources/academy/platform/expert_scraping_with_apify/solutions/saving_stats.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ slug: /expert-scraping-with-apify/solutions/saving-stats
1313

1414
The code in this solution will be similar to what we already did in the **Handling migrations** solution; however, we'll be storing and logging different data. First, let's create a new file called **Stats.js** and write a utility class for storing our run stats:
1515

16-
```javascript
16+
```js
1717
import Actor from 'apify';
1818

1919
class Stats {
@@ -51,7 +51,7 @@ module.exports = new Stats();
5151
5252
Cool, very similar to the **AsinTracker** class we wrote earlier. We'll now import **Stats** into our **main.js** file and initialize it along with the ASIN tracker:
5353
54-
```javascript
54+
```js
5555
// ...
5656
import Stats from './Stats.js';
5757

@@ -65,7 +65,7 @@ await Stats.initialize();
6565
6666
In order to keep track of errors, we must write a new function within the crawler's configuration called **failedRequestHandler**. Passed into this function is an object containing an **Error** object for the error which occurred and the **Request** object, as well as information about the session and proxy which were used for the request.
6767
68-
```javascript
68+
```js
6969
const crawler = new CheerioCrawler({
7070
proxyConfiguration,
7171
useSessionPool: true,
@@ -90,7 +90,7 @@ const crawler = new CheerioCrawler({
9090
9191
Now, we'll just increment our **totalSaved** count for every offer added to the dataset.
9292
93-
```javascript
93+
```js
9494
router.addHandler(labels.OFFERS, async ({ $, request }) => {
9595
const { data } = request.userData;
9696

@@ -116,7 +116,7 @@ router.addHandler(labels.OFFERS, async ({ $, request }) => {
116116
117117
Still, in the **OFFERS** handler, we need to add a few extra keys to the items which are pushed to the dataset. Luckily, all of the data required by the task is easily accessible in the context object.
118118
119-
```javascript
119+
```js
120120
router.addHandler(labels.OFFERS, async ({ $, request }) => {
121121
const { data } = request.userData;
122122

0 commit comments

Comments
 (0)