The features outlined below are all built with the DatArchive API. Please review and become comfortable traversing the documentation provided by the Beaker Browser website.
- clone this repository
- download the beaker browser
- go to
New +
button and click "from folder" - add your directory
- edit
profile.json
to update your profile - publish all changes
- copy your
dat://
url to the class spreadsheet and to yourprofile.json
file. - once the spreadsheet is full, feel free to copy the urls and add them to your
post.json
file.
a list of initial available functions found in build/network-interfacing.js
:
In order to use any of the functions below, you will need to construct a DatArchive instance with:
var archive = new DatArchive("dat://THE_URL_YOU_NEED")
This variable (archive
) can then be passed through the functions below. There are certain functions though, that might need a custom instance (rather than your dat url).
Most of the html you will write in this class will actually be in javascript and then appended to the DOM (i.e. your index.html
document). There are various methods to append html with javascript, but we will primarily be using the insertAdjacentHTML()
method with template literals.
- Read and view examples of
insertAdjacentHTML()
here. - Read and view examples of template literals here.
Example:
var yourElement = document.getElementById("ELEMENTID")
yourElement.insertAdjacentHTML('beforebegin', `
<h1>template literal</h1>
<p>this is a template literal denoted by the \` \` characters.</p>
<p class="a_class" style="color:red;">you can freely write and format html in here! :) </p>
`)
loadProfile(archive)
: get profile objectloadPosts(archive)
: get a list of a user's postsloadPostContent(archive, post)
: get content of each post and appendloadUsersCentral(archive, jsonName)
: get a list of users from an external source
the DatArchive API relies on Promises. We run an asynchronous (i.e. async
) function that calls an external source (usually another dat url) and then "wait" for a response.
This is done in the general format of:
var archive = new DatArchive("dat://THE_URL_YOU_NEED") // construct your instance
loadProfile(archive)
.then(function(returnedObject){
// do something with the returnedObject
console.log(returnedObject)
})
.catch(function(error){
// sometimes there is an error (a request as "timedout" or something was miswritten)
// it helps to have a catch that console logs any error for debugging
console.log(error)
})
A recursive function calls itself:
function yourFunction(yourVariable){
yourVariable++
console.log(yourVariable)
// and repeat:
if(yourVariable < 10){
yourFunction(yourVariable)
}
}
var counter = 0;
yourFunction(counter)
These functions are a little more complex. You will have to enter the build/network-interfacing.js
file to alter their template literals. Feel free to play around and mess them up—you can always re-download a clean copy!
usersProfiles(userCounter, userList, mountingContainer)
: use a list of users and return their profileuserAndTheirPosts(userCounter, userList, mountingContainer)
: use a list of users and return their profile + all their posts
A key part of any network is the posting interface. The DatArchive API has a wonderful method built in that allows a site to recognize if you're the owner. If you are, you're given special permissions (like writing new files!).
isOwner(archive)
: check if you are the site's owner (returns a boolean)isOwner()
is built out of thegetInfo()
method. Read more here.
writePost(archive, postSubmission)
: submit a post interface- this function uses the API's
writeFile()
method. Read more here.
- this function uses the API's
We referenced fritter's datastructure as a model for our network.