Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mskian committed Aug 20, 2022
0 parents commit dd13f19
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .eggignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.git*/**
.idea/**
.vscode/**
benchmarks/**
eggs-debug.log
.github
LICENSE
deno.json
.vscode
.gitignore
test.ts
score.ts
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Test Scrape

on:
push:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Clone repository
uses: actions/checkout@v2

- name: Setup Deno environment
uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- name: Setup Cache
uses: actions/cache@v3
with:
path: |
~/.deno
~/.cache/deno
key: ${{ runner.os }}-deno-${{ hashFiles('**/_config.ts', '**/import_map.json') }}

- name: Running Tools
run: |
deno run --allow-net --allow-read test.ts
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_cache
eggs-debug.log
score.ts
21 changes: 21 additions & 0 deletions .vscode/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# MIT License

Copyright (c) 2022 Santhosh Veer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"deno.enable": true,
"deno.lint": true,
"deno.unstable": true,
"deno.suggest.imports.hosts": {
"https://deno.land": true
}
}
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Deno Cheerio

[![Test Scrape](https://github.com/mskian/deno-cheerio-js/actions/workflows/test.yml/badge.svg)](https://github.com/mskian/deno-cheerio-js/actions/workflows/test.yml)
![Deno](https://img.shields.io/badge/Deno-464647?style=for-the-badge&logo=deno&logoColor=white)

Cheerio - Porting Cheerio Node Module To Deno using `esm.sh`

## Prerequisites

- Deno on your System <https://deno.land/#installation>

## Usage

- Cheerio Full Docs and usage - <https://cheerio.js.org/>

```js
import { cheerio } from "https://deno.land/x/denocheerio/mod.ts";

fetch(
"https://notes.santhoshveer.com/",
)
.then((result) => result.text())
.then((html) => {
const $ = cheerio.load(html);
const title = $('meta[property="og:title"]').attr("content") ||
$("title").text() || $('meta[name="title"]').attr("content");
const description = $('meta[property="og:description"]').attr("content") ||
$('meta[name="description"]').attr("content");
console.log(title);
console.log(description);
}).catch((error) => {
console.log(error);
});
```

## Testing

```sh
deno run --allow-net --allow-read test.ts

or

deno task test
```

## Credits

- cheerio Npm Module - <https://github.com/cheeriojs/cheerio>

## LICENSE

MIT
5 changes: 5 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tasks": {
"test": "deno run --allow-net --allow-read test.ts"
}
}
28 changes: 28 additions & 0 deletions egg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "https://x.nest.land/[email protected]/src/schema.json",
"name": "cheerio",
"entry": "./mod.ts",
"description": "Cheerio - Porting Cheerio Node Module To Deno",
"homepage": "https://github.com/mskian/deno-cheerio-js",
"version": "0.0.1",
"releaseType": null,
"unstable": false,
"unlisted": false,
"files": [
"README.md"
],
"ignore": [
".git",
".github",
"LICENSE",
"deno.json",
".vscode",
".gitignore",
"test.ts",
"score.ts"
],
"checkFormat": "deno fmt",
"checkTests": false,
"checkInstallation": false,
"check": true
}
9 changes: 9 additions & 0 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Deno Cheerio
* Cheerio - Porting Cheerio Node Module To Deno
* Convert using - https://esm.sh/
*/

import * as cheerio from "https://esm.sh/[email protected]";

export { cheerio };
17 changes: 17 additions & 0 deletions test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { cheerio } from "./mod.ts";

fetch(
"https://notes.santhoshveer.com/",
)
.then((result) => result.text())
.then((html) => {
const $ = cheerio.load(html);
const title = $('meta[property="og:title"]').attr("content") ||
$("title").text() || $('meta[name="title"]').attr("content");
const description = $('meta[property="og:description"]').attr("content") ||
$('meta[name="description"]').attr("content");
console.log(title);
console.log(description);
}).catch((error) => {
console.log(error);
});

0 comments on commit dd13f19

Please sign in to comment.