mirror of
https://github.com/leoncvlt/loconotion.git
synced 2024-08-30 18:12:12 +00:00
Moved bundles and switched to chromedriver-autoinstaller
This commit is contained in:
parent
c489e0a8c1
commit
511948dc3b
Binary file not shown.
@ -73,7 +73,8 @@ for (let i = 0; i < anchorLinks.length; i++) {
|
|||||||
id.slice(0, 8) + "-" + id.slice(8, 12) + "-" + id.slice(12, 16) + "-" + id.slice(16, 20) + "-" + id.slice(20);
|
id.slice(0, 8) + "-" + id.slice(8, 12) + "-" + id.slice(12, 16) + "-" + id.slice(16, 20) + "-" + id.slice(20);
|
||||||
anchorLink.addEventListener("click", (e) => {
|
anchorLink.addEventListener("click", (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
document.querySelector(targetBlockId).scrollIntoView({
|
console.log(targetBlockId);
|
||||||
|
document.querySelector(`div[data-block-id='${targetBlockId}']`).scrollIntoView({
|
||||||
behavior: "smooth",
|
behavior: "smooth",
|
||||||
block: "start",
|
block: "start",
|
||||||
});
|
});
|
@ -13,9 +13,10 @@ import hashlib
|
|||||||
import argparse
|
import argparse
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger("loconotion")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
import chromedriver_autoinstaller
|
||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
from selenium.webdriver.chrome.options import Options
|
from selenium.webdriver.chrome.options import Options
|
||||||
from selenium.common.exceptions import TimeoutException, NoSuchElementException
|
from selenium.common.exceptions import TimeoutException, NoSuchElementException
|
||||||
@ -23,7 +24,6 @@ try:
|
|||||||
from selenium.webdriver.common.by import By
|
from selenium.webdriver.common.by import By
|
||||||
from selenium.webdriver.support.ui import WebDriverWait
|
from selenium.webdriver.support.ui import WebDriverWait
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import toml
|
import toml
|
||||||
import cssutils
|
import cssutils
|
||||||
@ -214,23 +214,20 @@ class Parser():
|
|||||||
return cached_file
|
return cached_file
|
||||||
|
|
||||||
def init_chromedriver(self):
|
def init_chromedriver(self):
|
||||||
exec_extension = ".exe" if platform.system() == "Windows" else ""
|
chromedriver_path = self.args.get("chromedriver")
|
||||||
chromedriver_path = Path.cwd() / self.args.get("chromedriver")
|
if (not chromedriver_path):
|
||||||
|
try:
|
||||||
# add the .exe extension on Windows if omitted
|
chromedriver_path = chromedriver_autoinstaller.install()
|
||||||
if (not chromedriver_path.suffix):
|
except Exception as exception:
|
||||||
chromedriver_path = chromedriver_path.with_suffix(exec_extension)
|
log.critical(f"Failed to install the built-in chromedriver: {exception}\n" +
|
||||||
|
"download the correct version for your system at https://chromedriver.chromium.org/downloads" +
|
||||||
# check the chromedriver executable exists
|
"and use the --chromedriver argument to point to the chromedriver executable")
|
||||||
if (not chromedriver_path.is_file()):
|
sys.exit()
|
||||||
log.critical(f"Chromedriver not found at {chromedriver_path}." +
|
|
||||||
" Download the correct distribution at https://chromedriver.chromium.org/downloads")
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
|
log.info(f"Initialising chromedriver at {chromedriver_path}")
|
||||||
logs_path = (Path.cwd() / "logs" / "webdrive.log")
|
logs_path = (Path.cwd() / "logs" / "webdrive.log")
|
||||||
logs_path.parent.mkdir(parents=True, exist_ok=True)
|
logs_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
log.info("Initialising chrome driver")
|
|
||||||
chrome_options = Options()
|
chrome_options = Options()
|
||||||
chrome_options.add_argument("--headless")
|
chrome_options.add_argument("--headless")
|
||||||
chrome_options.add_argument("window-size=1920,1080")
|
chrome_options.add_argument("window-size=1920,1080")
|
||||||
@ -441,10 +438,10 @@ class Parser():
|
|||||||
injects_custom_tags("body")
|
injects_custom_tags("body")
|
||||||
|
|
||||||
# inject loconotion's custom stylesheet and script
|
# inject loconotion's custom stylesheet and script
|
||||||
loconotion_custom_css = self.cache_file("loconotion.css")
|
loconotion_custom_css = self.cache_file(Path("bundles/loconotion.css"))
|
||||||
custom_css = soup.new_tag("link", rel="stylesheet", href=str(loconotion_custom_css))
|
custom_css = soup.new_tag("link", rel="stylesheet", href=str(loconotion_custom_css))
|
||||||
soup.head.insert(-1, custom_css)
|
soup.head.insert(-1, custom_css)
|
||||||
loconotion_custom_js = self.cache_file("loconotion.js")
|
loconotion_custom_js = self.cache_file(Path("bundles/loconotion.js"))
|
||||||
custom_script = soup.new_tag("script", type="text/javascript", src=str(loconotion_custom_js))
|
custom_script = soup.new_tag("script", type="text/javascript", src=str(loconotion_custom_js))
|
||||||
soup.body.insert(-1, custom_script)
|
soup.body.insert(-1, custom_script)
|
||||||
|
|
||||||
@ -499,17 +496,18 @@ if __name__ == '__main__':
|
|||||||
# set up argument parser
|
# set up argument parser
|
||||||
parser = argparse.ArgumentParser(description='Generate static websites from Notion.so pages')
|
parser = argparse.ArgumentParser(description='Generate static websites from Notion.so pages')
|
||||||
parser.add_argument('target', help='The config file containing the site properties, or the url of the Notion.so page to generate the site from')
|
parser.add_argument('target', help='The config file containing the site properties, or the url of the Notion.so page to generate the site from')
|
||||||
parser.add_argument('--chromedriver', default='bin/chromedriver', help='Path to the chromedriver executable')
|
parser.add_argument('--chromedriver', help='Use a specific chromedriver executable instead of the auto-installing one')
|
||||||
parser.add_argument("--single-page", action="store_true", default=False, help="Only parse the first page, then stop")
|
parser.add_argument("--single-page", action="store_true", default=False, help="Only parse the first page, then stop")
|
||||||
parser.add_argument('--clean', action='store_true', default=False, help='Delete all previously cached files for the site before generating it')
|
parser.add_argument('--clean', action='store_true', default=False, help='Delete all previously cached files for the site before generating it')
|
||||||
parser.add_argument("-v", "--verbose", action="store_true", help="Shows way more exciting facts in the output")
|
parser.add_argument("-v", "--verbose", action="store_true", help="Shows way more exciting facts in the output")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# set up some pretty logs
|
# set up some pretty logs
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger("loconotion")
|
||||||
log.setLevel(logging.INFO if not args.verbose else logging.DEBUG)
|
log.setLevel(logging.INFO if not args.verbose else logging.DEBUG)
|
||||||
log_screen_handler = logging.StreamHandler(stream=sys.stdout)
|
log_screen_handler = logging.StreamHandler(stream=sys.stdout)
|
||||||
log.addHandler(log_screen_handler)
|
log.addHandler(log_screen_handler)
|
||||||
|
log.propagate = False
|
||||||
try:
|
try:
|
||||||
import colorama, copy
|
import colorama, copy
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
beautifulsoup4==4.9.1
|
beautifulsoup4==4.9.1
|
||||||
certifi==2020.4.5.1
|
certifi==2020.4.5.1
|
||||||
chardet==3.0.4
|
chardet==3.0.4
|
||||||
|
chromedriver-autoinstaller==0.2.0
|
||||||
colorama==0.4.3
|
colorama==0.4.3
|
||||||
cssutils==1.0.2
|
cssutils==1.0.2
|
||||||
idna==2.9
|
idna==2.9
|
||||||
|
Loading…
Reference in New Issue
Block a user