Get a list of all pages from `docs` directory? - javascript

I am trying to implement a "Get random page" link in Docusaurus. For that I would like to get a list of all available pages/page ids+path from the docs/ directory.
Does Docusaurus have a way to do this programmatically?

I did not find any native or plugin way to achieve this... Here is how I you do it:
PART 1
Once you built you docusaurus website, will be generated a sitemap.xml file.
This file is locate at the root directory of your site and contains all of the url of the doc pages.
Create a js function that read this file and parse it. Then get a random url open it.
TIP 1: https://www.w3schools.com/xml/xml_parser.asp
TIP 2: https://www.w3schools.com/jsref/met_win_open.asp
PART 2
Then, you can embed your JavaScript using the mdx function of docusaurus.
TIP: How can I add custom scripts in index.html's head part in Docusaurus V2?

Related

Javascript - read all filenames and output to html with hyperlink

I have a limited hosting server. I want to read the filetree (all files and folders) and create a hyperlink to them on a basic html page.
For clarity, I'm using Keybase, am publicly sharing files, but want to list them on an index.html page, not use their site's "filetree"
https://keybase.pub/example_user (keybase filetree)
https://example_user.keybase.pub (the index.html file)
The html file is in the root directory and I want to display all the (pdf) files in /subdir (and their sub-directories)
This isn't a "real" webserver. I'm looking for something easy and simple like a FOR loop on load within html
Thanks.
What you are trying to do is known as "screen scraping". If you do some googling on the keywords "javascript screen scraping" you will find lots of information and examples.
Basically, You fire off an AJAX request to retrieve the content of a page, parse that content to obtain the data your looking for, and then display that data in your page.

Script to create URL from file ID in Google Docs

I'm trying to figure out if there is a way using a script in a Google Doc to create a dynamic link to a Google Doc to download it as a PDF.
File links in Google Docs look like this:
https://docs.google.com/document/d/FILEID/edit
To download/save the file as a PDF this link is required:
https://docs.google.com/document/d/FILE_ID/export?format=pdf
So I'm wondering if it would be possible using a script to fetch the file ID and create the PDF link above and then recall that link in the actual document (as a link or bookmark?).
In the actual document it would for example say "Download as PDF", and would have a link to the script result for https://docs.google.com/document/d/FILE_ID/export?format=pdf.
I thought I'd reach out and see if someone knows if it can be done.
NOTE: All above links point to non-existent resources and are provided for illustration only.
Thanks

Update all href anchor links in folder of HTML files

I am using Gatsbyjs to generate a static site, this outputs a folder of static HTML files.
I have a requirement to host these HTML files on Microsoft SharePoint - this requires the .html to be converted to .aspx in order for them to run.
I have a postscript which updates all .html to .aspx (this works nicely).
However, all the generated links point to the folder:
link
In order for this to work on sharepoint, I need to update every href in each html file to point to the index.aspx file in each folder:
link
What's the best way to do on post build? Ideally, I'd like to include this as part of my post-build script. Can this be achieved with webpack? Or am I better off using something like JSDOM to loop through each file and update each of the links?
You are probably better off using cheerio, which is lighter than jsdom and supports most of the jquery syntax.
var html = fs.readFileSync(input.html);
const $ = cheerio.load(html);
var output = $('a[href="folder"').attr('href', '/folder/index.aspx').html();

trying to /how to work with dashboard template SB-Admin-BS4-Angular-4

download template from
https://github.com/jyinterfly/SB-Admin-BS4-Angular-4-master
sample demo
http://rawgit.com/start-angular/SB-Admin-BS4-Angular-4/master/dist/dashboard
I found the SB-Admin-BS4-Angular-4-master template and downloaded to my local c:\drive. I want to edit the index.html page however the page is blank. and in the online demo dashboard the other webpage htmls don’t exist in the download project.
I like the look and would like to use the dashboard webpage SB-Admin-BS4-Angular-4-master
For example I downloaded the dashboard template sb-admin-bs-4. Located the index.html. The page loads with objects I can edit.
I can locate all the html pages displayed in the demo dashboard.
Have I missed something. What do I need to do to get started.
Im a developer however new to javascript and dashboards
TIA
--dd
The project is developed on angular 4. The pages(components) your looking for can be found on the following path project_folder/src/app and the styles can be found on the following path project_folder/src/styles/. If your not familiar with angular 4, Please go and look at angular.io site.

Google Apps Script How to link to JS or CSS file on Google Drive

Can I keep style.css or anyscript.js hosted on a folder on Google Drive and then include the script with a link to the file in Drive? If so.. how?
And here I mean GAS for use on Google Sites... so the script is not located in Google Drive
Google seem to have changed it.
At the time of writing, a link to the raw data works with the following link format:
https://drive.google.com/uc?id=YOUR_DOCUMENT_ID
UPDATE: As of August 31, 2015 this technique has been deprecated by Google.
Google recent made it possible host a file publicly on Google Drive:
Create a folder in Google Drive
Put any files you want to access publicly in the folder
Share it publicly (needs to be "Public on the web") and copy the folder ID from the "Link to Share". For example, the folder ID from this link: https://docs.google.com/folder/d/0B5AR8ct5SZfSTDZTQjNNVXR4RWM/edit ... is: 0B5AR8ct5SZfSTDZTQjNNVXR4RWM
The URL for each file will be https://googledrive.com/host/ followed by the folder id followed by the filename. For example: if you saved style.css in the folder in step #1: https://googledrive.com/host/0B5AR8ct5SZfSTDZTQjNNVXR4RWM/style.css
What about Google's own recommendation in the HTML Service Best practices, for Separating HTML, CSS and Javascript?
It still works, the URLs just look a bit different.
Answered already over here, but the steps are:
On the folder with your intended file (e.g. FILE.css), hit Sharing Settings, then Advanced, then select "Public on the web - Anyone on the Internet can find and view."
In the URL bar (or share link), copy everything after the drive.google.com/drive/u/0/folders/
Use that ID to replace the XX-XXXXXXXXXXXXX in: http://googledrive.com/host/XX-XXXXXXXXXXXXX/FILE.css
Navigate to the appended URL in Step 3 and you will now see your raw data.
Credit to #chris.huh at: https://productforums.google.com/forum/#!topic/drive/MyD7dgLJaEo
I found out that the direct link workaround has changed a bit. You can download any file using the following url now:
https://drive.google.com/uc?export=download&id=[PutYourIdHere]
This is how you extract the id of your file:
https://drive.google.com/file/d/1gIax1-2397HJFLSJFOIUWEIJ23/view?usp=sharing
Here 1gIax1-2397HJFLSJFOIUWEIJ23 is the ID

Categories

Resources