Skip to content

Commit

Permalink
Merge pull request #5 from markbattistella/js-scope
Browse files Browse the repository at this point in the history
v5.0.4 - fixes the global variable clashing
  • Loading branch information
markbattistella authored May 16, 2023
2 parents 144abc9 + 2899bd7 commit 66feafe
Show file tree
Hide file tree
Showing 11 changed files with 255 additions and 46 deletions.
1 change: 0 additions & 1 deletion .github/README.md

This file was deleted.

185 changes: 185 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
<div align="center">

# docsify.js sidebar footer

</div>

This plugin enhances your website's sidebar or page by creating a footer area where you can display important information. It automatically updates the copyright year or range, allows you to include your name or company with a URL, and provides links to a privacy policy, terms of service, and cookies policy pages. By utilising this plugin, you can easily showcase relevant legal information, personalise your website, and promote transparency and compliance.

## Installation

!> **Note: There are breaking changes in the configuration from `v4.x` to `v5.x`. Please take the time to read all the documentation before upgrading**

### Update `index.html` file

Assuming you have a working [docsify](https://docsify.js.org/) framework set up, it is easy to use the plugin.

1. Add one of the following script tags to your `index.html` via either CDN or downloading it and using it locally:

```html
<!-- unpkg.com -->
<script src="https://unpkg.com/@markbattistella/docsify-sidebarfooter@latest"></script>

<!-- jsDelivr -->
<script src="https://cdn.jsdelivr.net/npm/@markbattistella/docsify-sidebarfooter@latest"></script>

<!-- locally -->
<script src="docsify-sidebar.min.js"></script>
```

1. In docsify setup configure the plugin:

```js
<script>
window.$docsify = {
autoFooter: {
// the name you wish to display as the copyright holder
name: String,
// the URL (personal or company) which clicking the `name` goes to
url: String,
// the start year of copyright
copyYear: String,
// show the privacy policy link
policy: Bool | String,
// show the terms of service link
terms: Bool | String,
// show the cookies policy link
cookies: Bool | String,
// use your own css styles or the built in ones
customStyle: Bool | String
}
};
</script>
```

### Additional files

#### Default

If you set the `policy`, `terms`, or `cookies` options to `true` the URL links for those pages will look for the markdown files directly next to the `index.html` file:

```js
// ... other config
policy: true,
terms: true,
cookies: true,
// ... other config
```

```md
- index.html --> https://your-awesome-site.com/#/
- _policy.md --> https://your-awesome-site.com/#/_policy
- _terms.md --> https://your-awesome-site.com/#/_terms
- _cookies.md --> https://your-awesome-site.com/#/_cookies
```

#### Sub-folder

However, if you enter a string it will append that to the base URL of your website:

```js
// ... other config
policy: 'site/policy',
terms: 'site/terms',
cookies: 'site/cookies',
// ... other config
```

```md
- index.html --> https://your-awesome-site.com/#/
- site/
\__ policy.md --> https://your-awesome-site.com/#/site/policy
\__ terms.md --> https://your-awesome-site.com/#/site/terms
\__ cookies.md --> https://your-awesome-site.com/#/site/cookies
```

#### External links

If you host your policy, terms, or cookies messages on an external website (or need to link to a parent company policy) you can add them in as the full URL:

```js
// ... other config
policy: "https://my-other-website.com/policy",
terms: "https://my-other-website.com/terms",
cookies: "https://my-other-website.com/cookies",
// ... other config
```

These will open those pages in a new tab directly.

## Configuration

There are some options available for the `docsify-sidebarfooter`:

| Setting | Type | Options |
|---------------|----------------|------------------------------------|
| `name` | String | your name or company |
| `url` | String | url you want the `name` to link to |
| `copyYear` | String | first year of copyright |
| `policy` | Bool or String | - `false` hides it from the site<br/>- `true` defaults to `_policy.md`<br/>- a custom string will direct to that |
| `terms` | Bool or String | - `false` hides it from the site<br/>- `true` defaults to `_terms.md`<br/>- a custom string will direct to that |
| `cookies` | Bool or String | - `false` hides it from the site<br/>- `true` defaults to `_cookies.md`<br/>- a custom string will direct to that |
| `customStyle` | Bool or String | - `false` uses in-built css (sidebar styled)<br/>- `true` applies no styles, you can create your own<br/>- `sidebar` uses the in-built css designed for the sidebar<br/>- `body` uses the in-built css designed for the body |

## Usage

### Sidebar

At the bottom of your `_sidebar.md` file add the following code:

```html
<footer id="mb-footer"></footer>
```

### Body

Under the `<div id="app"></div>` in your `index.html` file, add the following code:

```html
<footer id="mb-footer"></footer>
```

## Styling

The links container is sectioned into different classes for you to customise as much (or little) as you wish.

```html
<footer id="mb-footer">
<div class="footer-container">
<div class="footer-text">
<span class="footer-text-copyright">
Copyright © YYYY-YYYY
</span>
<span class="footer-text-author">
<a target="_blank" href="">Your website name</a>
</span>
</div>
<div class="footer-link">
<span class="footer-links-policy">
<a href="">Policy</a>
</span>
<span class="footer-links-terms">
<a href="">Terms</a>
</span>
<span class="footer-links-cookies">
<a href="">Cookies</a>
</span>
</div>
</div>
</footer>
```

## Contributing

1. Clone the repo:<br>`git clone https://github.com/markbattistella/docsify-sidebarFooter.git`
2. Create your feature branch:<br>`git checkout -b my-feature`
3. Commit your changes:<br>`git commit -am 'Add some feature'`
4. `Push` to the branch:<br>`git push origin my-new-feature`
5. Submit the `pull` request
4 changes: 2 additions & 2 deletions dist/docsify-sidebar.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This plugin enhances your website's sidebar or page by creating a footer area wh

## Installation

!> **Note: There are breaking changes in the configuration from `v4.x` to `v5.x`. Please take the time to read all the documentation before upgrading**

### Update `index.html` file

Assuming you have a working [docsify](https://docsify.js.org/) framework set up, it is easy to use the plugin.
Expand Down
82 changes: 50 additions & 32 deletions docs/dist/docsify-sidebar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! docsify-sidebar.js v5.0.3 | (c) Mark Battistella */
/*! docsify-sidebar.js v5.0.4 | (c) Mark Battistella */
'use strict';

// MARK: - check if object exists and is not empty
Expand All @@ -13,31 +13,44 @@ function doesObjectExists(obj) {


// MARK: - update the `options` object
function getFooter(options) {
function getFooter(footerOptions) {

// -- get this year
let date = new Date().getFullYear();

// -- update the variables
options.name ? options.name : null;
options.url ? options.url : null;
options.copyYear ? options.copyYear : date;
options.policy ? options.policy : false;
options.terms ? options.terms : false;
options.cookies ? options.cookies : false;
options.customStyle ? options.customStyle : false;
footerOptions.name ? footerOptions.name : null;
footerOptions.url ? footerOptions.url : null;
footerOptions.copyYear ? footerOptions.copyYear : date;
footerOptions.policy ? footerOptions.policy : false;
footerOptions.terms ? footerOptions.terms : false;
footerOptions.cookies ? footerOptions.cookies : false;
footerOptions.customStyle ? footerOptions.customStyle : false;
}


// defaults - and setup
const options = {
// -- defaults
const footerOptions = {
name: '',
url: '',
copyYear: '',
policy: true,
terms: true,
cookies: true,
customStyle: false
},

// -- errors
footerError = {

// -- error: when something that shouldn't happen, happens
unknownError: 'ERROR: sidebar-footer plugin - unknown error',

// -- error: configuration not set
configNotSet: `ERROR: sidebar-footer plugin - configuration not set\n\t\t>> this happens when the autoFooter is not found in the index.html file`,

// -- error: configuration is empty object
configIsEmpty: `ERROR: sidebar-footer plugin - configuration is empty\n\t\t>> please consult the documentation for the settings needed`
};


Expand All @@ -48,29 +61,29 @@ function autoFooter(hook, vm) {
hook.init(function () {

// -- initialise the options
getFooter(options);
getFooter(footerOptions);


// -- check the options for bool or string
if (typeof options.customStyle === "boolean" || typeof options.customStyle === "string") {
if (typeof footerOptions.customStyle === "boolean" || typeof footerOptions.customStyle === "string") {

// -- dont continue if using custom styles
if ((typeof options.customStyle === "boolean" && options.customStyle === true)) {
if ((typeof footerOptions.customStyle === "boolean" && footerOptions.customStyle === true)) {
return;
}

// -- global style
let style = `#mb-footer { border-top: 1px solid; font-size: 0.8em; line-height: 1.5; transition: all var(--sidebar-transition-duration) ease-out; }`;

// -- custom style for sidebar
if ((typeof options.customStyle === "boolean" && options.customStyle === false) ||
(options.customStyle === "sidebar")
if ((typeof footerOptions.customStyle === "boolean" && footerOptions.customStyle === false) ||
(footerOptions.customStyle === "sidebar")
) {
style += `#mb-footer { padding-top: 1.5rem; margin-top: 1.5rem; } #mb-footer .footer-text, #mb-footer .footer-text a { font-weight: bold; }`;
}

// -- custom style for sidebar
if (options.customStyle === "body") {
if (footerOptions.customStyle === "body") {

// --> if there is a sidebar
if( $docsify.loadSidebar || $docsify.loadSidebar === null || !$docsify.hideSidebar ) {
Expand Down Expand Up @@ -173,17 +186,17 @@ function autoFooter(hook, vm) {
// -- text
copyright = (
`<span class="footer-text-copyright">Copyright &copy; ${
options.copyYear && options.copyYear <= date
? `${options.copyYear}${options.copyYear < date ? "&#45;" + date : ""}`
footerOptions.copyYear && footerOptions.copyYear <= date
? `${footerOptions.copyYear}${footerOptions.copyYear < date ? "&#45;" + date : ""}`
: date
}</span>`
),
author = createLink( options.url, options.name, '', 'footer-text-author'),
author = createLink( footerOptions.url, footerOptions.name, '', 'footer-text-author'),

// -- links
policyURL = createLink(options.policy, 'Policy', '_policy', 'footer-links-policy'),
termsURL = createLink(options.terms, 'Terms', '_terms', 'footer-links-terms' ),
cookiesURL = createLink(options.cookies, 'Cookies', '_cookies', 'footer-links-cookies'),
policyURL = createLink(footerOptions.policy, 'Policy', '_policy', 'footer-links-policy'),
termsURL = createLink(footerOptions.terms, 'Terms', '_terms', 'footer-links-terms' ),
cookiesURL = createLink(footerOptions.cookies, 'Cookies', '_cookies', 'footer-links-cookies'),

// output
output = (
Expand All @@ -199,22 +212,27 @@ function autoFooter(hook, vm) {


// MARK: - check options is defined and not empty
if (typeof options !== 'undefined' && doesObjectExists(options)) {
if (typeof footerOptions !== 'undefined' && doesObjectExists(footerOptions)) {

// -- find footer plugin options
window.$docsify.autoFooter = Object.assign(
options,
footerOptions,
window.$docsify.autoFooter
);
window.$docsify.plugins = [].concat(autoFooter, window.$docsify.plugins);

} else {

// -- log the error
console.error(
"ERROR: sidebar-footer configuration not set" + "\n" +
"This error appears when:" + "\n" +
" - the `autoSidebar` not found index.html file" + "\n" +
" - the `autoSidebar` is empty"
);
// --> config not set in `index.html`
if (typeof headerOptions === 'undefined') {
throw footerError.configNotSet
}

// --> config is empty object
if (!doesObjectExists(headerOptions)) {
throw footerError.configNotSet
}

// --> some other error
throw footerError.unknownError;
}
Loading

0 comments on commit 66feafe

Please sign in to comment.