Git Product home page Git Product logo

aloisdg / stacktribution Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 0.0 1.14 MB

A tiny webapp to generate proper attribution to a Stack Overflow's answer.

Home Page: https://stacktribution.vercel.app/

License: MIT License

Shell 0.22% JavaScript 80.50% TypeScript 19.06% CSS 0.22%
nextjs react tailwindcss typescript stackoverflow stackoverflow-api stackoverflow-answer stackoverflow-questions hacktoberfest hacktoberfest-accepted

stacktribution's Introduction

Stacktribution

Proper attribution done fast.

I realise that most people don't respect attribution rules from Stack Overflow. Stacktribution is a small web app to help with that. Beside compliance, it fixes some trouble by saving answers next to the source code.

meme
When you run into the same issue years later
comments
Add the link to your code

Demo

demo_stacktribution

StackExchange's rules

Attribution is required.

You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).

There are not an official way to do it, but here are the rules:

So let me clarify what Stack Overflow means by attribution. If you republish a content, they require that you:

  1. Visually indicate that the content is from Stack Overflow or the Stack Exchange network in some way. It doesn’t have to be obnoxious; a discreet text blurb is fine.
  2. Hyperlink directly to the original question on the source site (e.g., http://stackoverflow.com/questions/12345)
  3. Show the author names for every question and answer
  4. Hyperlink each author name directly back to their user profile page on the source site (e.g., http://stackoverflow.com/users/12345/username)

From that, I created some compliant templates you can fill automaticaly then copy/paste above any snippet from Stack Overflow inserted in your code base.

Requirements

  • Node.js and npm

Getting started

Run the following command on your local environment:

git clone --depth=1 https://github.com/ixartz/Next-js-Boilerplate.git my-project-name
cd my-project-name
npm install

Then, you can run locally in development mode with live reload:

npm run dev

Open http://localhost:3000 with your favorite browser to see your project.

.
├── README.md                # README file
├── next.config.js           # Next JS configuration
├── public                   # Public folder
│   └── assets
│       └── images           # Image used by default template
├── src
│   ├── layout               # Atomic layout components
│   ├── pages                # Next JS pages
│   ├── styles               # PostCSS style folder with Tailwind
│   ├── templates            # Default template
│   └── utils                # Utility folder
├── tailwind.config.js       # Tailwind CSS configuration
└── tsconfig.json            # TypeScript configuration

VSCode information (optional)

If you are VSCode users, you can have a better integration with VSCode by installing the suggested extension in .vscode/extension.json. The starter code comes up with Settings for a seamless integration with VSCode. The Debug configuration is also provided for frontend and backend debugging experience.

Pro tips: if you need a project wide type checking with TypeScript, you can run a build with Cmd + Shift + B on Mac.

Contributions

Everyone is welcome to contribute to this project. Feel free to open an issue if you have question or found a bug.

License

Licensed under the MIT License, Copyright © 2020

See LICENSE for more information.


Made with CreativeDesignsGuru's template

stacktribution's People

Contributors

aloisdg avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

stacktribution's Issues

Implement PoC

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Stattribution</title>
    <link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet">

    <link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/themes/prism.min.css" rel="stylesheet" />
    <style>
      html, body {height: 100%;}

      a { border-bottom: 2px solid black;}
    </style>
</head>
<body class="grid place-items-center">
  <main style="width: 700px;">
    <div class="shadow-md rounded-md">

      <div class="p-5 flex flex-col">
          <h5 class="text-xl font-semibold mb-2">Stattribution</h5>

          <div class="mb-3 pt-0">
            <label for="answerIdInput">Answer id or url:
            <input  value="6176851" id="answerIdInput" type="text" placeholder="6865024"
              class="px-2 py-1 placeholder-gray-400 text-gray-600 relative bg-white bg-white rounded text-sm border border-gray-400 outline-none focus:outline-none focus:ring w-full" />
            </label>
            </div>
            <label class="mb-3"> Select your attribution's flavor:
            <select id="docType" class="block w-full text-gray-700 py-2 px-3 border border-gray-300 bg-white rounded-md shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500">
              <option>xmlDoc</option>
              <option>jsDoc</option>
            </select></label>
          <button
          id="search"
              class="bg-purple-500 text-white active:bg-purple-600 font-bold uppercase text-xs px-4 py-2 rounded shadow hover:shadow-md outline-none focus:outline-none mr-1 mb-1 ease-linear transition-all duration-150"
              type="button">
              search
          </button>

          

<pre>/// &lt;remarks&gt;
<code id="output" class="language-xml-doc"></code>
/// &lt;/remarks&gt;</pre>
      </div>
  </div>

</main>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/prism.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/components/prism-xml-doc.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/plugins/autoloader/prism-autoloader.min.js"></script>
    <script>
const getYearFromUnix = unixDate => new Date(unixDate * 1000).getFullYear()

document.querySelector('#search').onclick = () => {
  const answerId = document.querySelector('#answerIdInput').value.trim();
  const model = {"answererName":"Ilmari Karonen","answererProfile":"https://stackoverflow.com/users/411022/ilmari-karonen","answerUrl":"https://stackoverflow.com/a/6865024/1248177","questionUrl":"https://stackoverflow.com/q/6864991/1248177","questionTitle":"How to get the size of a number in .net?","license":"CC BY-SA 3.0","licenseUrl":"https://creativecommons.org/licenses/by-sa/4.0/", "answerYear": getYearFromUnix(1515157048)};

  // fetch(`https://api.stackexchange.com/2.3/answers/${answerId}?site=stackoverflow`)
  //   .then(response => response.json())
  //   .then(json => {
  //     const data = json.items[0];
  //     const model = {
  //       answererName: data.owner.display_name,
  //       answererProfile: data.owner.link,
  //       answerUrl: `https://stackoverflow.com/a/${data.answer_id}/1248177`,
  //       questionUrl: `https://stackoverflow.com/q/${data.question_id}/1248177`,
  //       questionTitle: "How to validate a credit card number",
  //       license: data.content_license, // "CC BY-SA 4.0"
  //       licenseUrl: 'https://creativecommons.org/licenses/by-sa/4.0/', //hopefully
  //     };
  //     fetch(`https://api.stackexchange.com/2.3/questions/${data.question_id}?site=stackoverflow`)
  //       .then(response => response.json())
  //       .then(json => {
  //         const questionTitle = json.items[0].title;
  //         model.questionTitle = questionTitle;
  //         console.log(JSON.stringify(model));
          const xmlDoc = `/// Inspired from <a href="${model.answererProfile}">${model.answererName}</a>'s
/// <a href="${model.answerUrl}">answer</a> published under <a href="${model.licenseUrl}">${model.license}</a>
/// on <a href="${model.questionUrl}">${model.questionTitle}</a>.`;

const jsDoc = `/**
 * @author ${model.answererName} <${model.answererProfile}>
 * @copyright ${model.answerYear} ${model.answererName}
 * @license ${model.license}
 * @see {@link ${model.answerUrl}|${model.questionTitle}}
 */`;

 const remark = document.querySelector("#docType").value === "xmlDoc" ? xmlDoc : jsDoc;

          document.querySelector('#output').textContent = remark;
    //     });
    // });
};
    </script>
</body>
</html>

Insert state machine

fetchMachine.ts

import { createMachine, assign } from "xstate";

interface FetchContext {
  input: string;
  output: string;
}

const fetchifetch = async (input: string) => {
  console.log(input);
  return await fetch(
    "https://jsonplaceholder.typicode.com/todos/1"
  ).then((response) => response.json());
};

export const fetchMachine = createMachine<FetchContext>({
  initial: "idle",
  context: {
    output: "wesh",
    input: undefined
  },
  states: {
    idle: {
      on: {
        FETCH: "loading",
        UPDATEID: {
          actions: assign({
            input: (_, event) => {
              console.log("event", event.value);
              return event.value;
            }
          })
        }
      }
    },
    loading: {
      invoke: {
        src: (context, event) => fetchifetch(context.input),
        onDone: {
          target: "fetch",
          actions: assign({
            output: (_, event) => event.data.title
          })
        },
        onError: {
          target: "idle"
        }
      },
      on: {
        FETCHED_SUCCESSFULLY: {
          target: "idle"
        }
      }
    },
    fetch: {
      on: {
        CLOSE: "idle"
      }
    }
  }
});

index.tsx

import "./styles.css";
import * as React from "react";
import * as ReactDOM from "react-dom";
import { useMachine } from "@xstate/react";
import { fetchMachine } from "./fetchMachine";

function App() {
  const [current, send] = useMachine(fetchMachine);
  const { output, input } = current.context;

  return (
    <div className="App">
      <h1>XState React Template</h1>
      <br />
      <input
        disabled={current.matches("loading")}
        defaultValue="yo"
        onChange={(e) => {
          send("UPDATEID", { value: e.currentTarget.value });
        }}
      />
      <button
        disabled={current.matches("loading")}
        onClick={() => send("FETCH")}
      >
        click to fetch
      </button>

      <div>{input}</div>
      <div>{output}</div>
    </div>
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

https://codesandbox.io/s/gifted-parm-u9dys?file=/src/index.tsx

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.